File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88 "io"
99 "reflect"
1010 "sync"
11+ "sync/atomic"
1112)
1213
1314// Error represents a JSON-RPC error response
@@ -54,7 +55,7 @@ type Client struct {
5455 mu sync.Mutex
5556 pendingRequests map [string ]chan * Response
5657 requestHandlers map [string ]RequestHandler
57- running bool
58+ running atomic. Bool
5859 stopChan chan struct {}
5960 wg sync.WaitGroup
6061 processDone chan struct {} // closed when the underlying process exits
@@ -97,17 +98,17 @@ func (c *Client) getProcessError() error {
9798
9899// Start begins listening for messages in a background goroutine
99100func (c * Client ) Start () {
100- c .running = true
101+ c .running . Store ( true )
101102 c .wg .Add (1 )
102103 go c .readLoop ()
103104}
104105
105106// Stop stops the client and cleans up
106107func (c * Client ) Stop () {
107- if ! c .running {
108+ if ! c .running . Load () {
108109 return
109110 }
110- c .running = false
111+ c .running . Store ( false )
111112 close (c .stopChan )
112113
113114 // Close stdout to unblock the readLoop
@@ -298,14 +299,14 @@ func (c *Client) readLoop() {
298299
299300 reader := bufio .NewReader (c .stdout )
300301
301- for c .running {
302+ for c .running . Load () {
302303 // Read Content-Length header
303304 var contentLength int
304305 for {
305306 line , err := reader .ReadString ('\n' )
306307 if err != nil {
307308 // Only log unexpected errors (not EOF or closed pipe during shutdown)
308- if err != io .EOF && c .running {
309+ if err != io .EOF && c .running . Load () {
309310 fmt .Printf ("Error reading header: %v\n " , err )
310311 }
311312 return
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ cd "$(dirname "$0")"
4343echo " === Running Go SDK E2E Tests ==="
4444echo
4545
46- go test -v ./...
46+ go test -v ./... -race
4747
4848echo
4949echo " ✅ All tests passed!"
You can’t perform that action at this time.
0 commit comments