Repository navigation
Commit 53ce82f
committed
fix(mcp): set stdio to binary mode on Windows
On Windows, stdin/stdout default to text mode, which translates LF to CRLF
on write and CRLF to LF on read. The MCP framing layer counts bytes for
Content-Length, so any translated byte makes the declared length disagree
with the actual payload. The subsequent fread() then waits for bytes that
never arrive and the server hangs with no error.
The symptom is a native MCP server that connects, handshakes, and then stops
responding on the first message containing a newline -- which in practice is
every real request. It reproduces on Windows only, and it looks like a client
timeout rather than a server bug, so it is easy to misattribute.
Fix: call _setmode(_O_BINARY) on both descriptors at the top of
cbm_mcp_server_run, guarded by #ifdef _WIN32. No behaviour change on POSIX.
Verified on Windows 11 (26200): built and running continuously since
2026-07-30 with no further hangs.
Note for maintainers: _O_BINARY is documented as coming from <fcntl.h>, which
this file includes only in the #else (non-Windows) branch. It resolves today
via transitive inclusion through <windows.h>, so the build is fine as-is --
but an explicit #include <fcntl.h> in the _WIN32 branch would make that
independent of Windows SDK header layout. Left out of this patch to keep the
change minimal; happy to add it if preferred.
Signed-off-by: ahmadgamal15-art <ahmad.gamal15@gmail.com>1 parent ee9833d commit 53ce82f
1 file changed
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11177 | 11177 | | |
11178 | 11178 | | |
11179 | 11179 | | |
| 11180 | + | |
| 11181 | + | |
| 11182 | + | |
| 11183 | + | |
| 11184 | + | |
| 11185 | + | |
| 11186 | + | |
11180 | 11187 | | |
11181 | 11188 | | |
11182 | 11189 | | |
| |||
0 commit comments