Commit d250b38
fix(server): resolve stdio server context cancellation bug (#331)
* fix(server): resolve stdio server context cancellation bug
Fix a critical bug in the stdio server's readNextLine function that was
causing "Error reading input" and "context cancelled" errors when Claude
Desktop attempted to connect to MCP servers.
The issue was in the select-default pattern that would immediately bypass
context cancellation checks and proceed with blocking ReadString operations
even when the context was cancelled. This prevented proper cleanup and
caused connection failures.
Changes:
- Remove problematic select-default pattern in readNextLine goroutine
- Simplify the read logic to directly call reader.ReadString('\n')
- Maintain proper done channel handling for result communication
- Ensure context cancellation is respected throughout the read operation
This resolves connection issues introduced in version 0.30.0 where the
stdio transport became unreliable for client connections.
Fixes: stdio server connection failures with Claude Desktop
* refactor: remove redudant signaling channels
---------
Co-authored-by: Marcos <marcos@atani.com>1 parent d5847c0 commit d250b38
1 file changed
Lines changed: 11 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
| 200 | + | |
| 201 | + | |
216 | 202 | | |
217 | 203 | | |
218 | 204 | | |
219 | 205 | | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
225 | 209 | | |
226 | 210 | | |
227 | 211 | | |
| |||
0 commit comments