Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions go/internal/jsonrpc2/jsonrpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"reflect"
"sync"
"sync/atomic"
)

// Error represents a JSON-RPC error response
Expand Down Expand Up @@ -54,7 +55,7 @@ type Client struct {
mu sync.Mutex
pendingRequests map[string]chan *Response
requestHandlers map[string]RequestHandler
running bool
running atomic.Bool
stopChan chan struct{}
wg sync.WaitGroup
processDone chan struct{} // closed when the underlying process exits
Expand Down Expand Up @@ -97,17 +98,17 @@ func (c *Client) getProcessError() error {

// Start begins listening for messages in a background goroutine
func (c *Client) Start() {
c.running = true
c.running.Store(true)
c.wg.Add(1)
go c.readLoop()
}

// Stop stops the client and cleans up
func (c *Client) Stop() {
if !c.running {
if !c.running.Load() {
return
}
c.running = false
c.running.Store(false)
close(c.stopChan)

// Close stdout to unblock the readLoop
Expand Down Expand Up @@ -298,14 +299,14 @@ func (c *Client) readLoop() {

reader := bufio.NewReader(c.stdout)

for c.running {
for c.running.Load() {
// Read Content-Length header
var contentLength int
for {
line, err := reader.ReadString('\n')
if err != nil {
// Only log unexpected errors (not EOF or closed pipe during shutdown)
if err != io.EOF && c.running {
if err != io.EOF && c.running.Load() {
fmt.Printf("Error reading header: %v\n", err)
}
return
Expand Down
2 changes: 1 addition & 1 deletion go/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ cd "$(dirname "$0")"
echo "=== Running Go SDK E2E Tests ==="
echo

go test -v ./...
go test -v ./... -race

echo
echo "✅ All tests passed!"
Loading