Skip to content

Commit 119a583

Browse files
authored
mcp: address some comments from #234 (#248)
I inadvertently merged #234 without pushing my latest patches. This CL adds the missing changes.
1 parent cb27392 commit 119a583

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

mcp/cmd_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ func TestServerInterrupt(t *testing.T) {
129129
}()
130130

131131
// send a signal to the server process to terminate it
132-
cmd.Process.Signal(os.Interrupt)
132+
if err := cmd.Process.Signal(os.Interrupt); err != nil {
133+
t.Fatal(err)
134+
}
133135

134136
// wait for the server to exit
135137
// TODO: use synctest when available
@@ -162,6 +164,11 @@ func TestStdioContextCancellation(t *testing.T) {
162164
}
163165

164166
// Sleep to make it more likely that the server is blocked in the read loop.
167+
//
168+
// This sleep isn't necessary for the test to pass, but *was* necessary for
169+
// it to fail, before closing was fixed. Unfortunately, it is too invasive a
170+
// change to have the jsonrpc2 package signal across packages when it is
171+
// actually blocked in its read loop.
165172
time.Sleep(100 * time.Millisecond)
166173

167174
onExit := make(chan struct{})
@@ -170,7 +177,9 @@ func TestStdioContextCancellation(t *testing.T) {
170177
close(onExit)
171178
}()
172179

173-
cmd.Process.Signal(os.Interrupt)
180+
if err := cmd.Process.Signal(os.Interrupt); err != nil {
181+
t.Fatal(err)
182+
}
174183

175184
select {
176185
case <-time.After(5 * time.Second):

mcp/transport.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ func newIOConn(rwc io.ReadWriteCloser) *ioConn {
318318
// Start a goroutine for reads, so that we can select on the incoming channel
319319
// in [ioConn.Read] and unblock the read as soon as Close is called (see #224).
320320
//
321-
// This leaks a goroutine, but that is unavoidable since AFAIK there is no
322-
// (easy and portable) way to guarantee that reads of stdin are unblocked
323-
// when closed.
321+
// This leaks a goroutine if rwc.Read does not unblock after it is closed,
322+
// but that is unavoidable since AFAIK there is no (easy and portable) way to
323+
// guarantee that reads of stdin are unblocked when closed.
324324
go func() {
325325
dec := json.NewDecoder(rwc)
326326
for {

0 commit comments

Comments
 (0)