You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 28, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 28, 2026. It is now read-only.
Sometimes a closed Socket::Shared reads indefinitely and does not close session endpoint (part two) #154
I'm still having this issue sometimes, at least on Mac OS X (Sonoma 14.0). I'm using commit 82beeea and there doesn't seem to have been any relevant changes since then 82beeea...main
Here's an example server:
hello_debugger.cpp
[I know it's not the best code with the condition variables but it shows the issue I'm facing]
When I run the server and nc localhost 12345 and then Ctrl+C the nc process, my CPU usage flies through the roof, and it looks like there is still an infinite read:
* thread #6, stop reason = breakpoint 3.1
* frame #0: 0x000000010008a520 hello_debugger`dap::Socket::Shared::read(this=0x000000013ef044e8, buffer=0x0000000170142c78, bytes=15) at socket.cpp:210:13
frame #1: 0x000000010000d678 hello_debugger`dap::ContentReader::buffer(this=0x0000000140104390, bytes=15) at content_stream.cpp:151:27
frame #2: 0x000000010000d8b4 hello_debugger`dap::ContentReader::scan(this=0x0000000140104390, seq="Content-Length:", len=15) at content_stream.cpp:96:10
frame #3: 0x000000010000d4c0 hello_debugger`dap::ContentReader::scan(this=0x0000000140104390, str="Content-Length:") at content_stream.cpp:107:10
frame #4: 0x000000010000d1d8 hello_debugger`dap::ContentReader::read(this=0x0000000140104390) at content_stream.cpp:56:10
Again, the recv() call is returning 0 on the closed socket:
I say sometimes this issue happens because sometimes the session ClosedHandler does execute ... other times, it hangs in this loop forever. Under no circumstance is the session error handler triggered.
-exec bt
* thread #4, stop reason = breakpoint 5.1
* frame #0: 0x000000010008aaf8 hello_debugger`(anonymous namespace)::errored(s=4) at socket.cpp:84:10
frame #1: 0x000000010008a2f8 hello_debugger`dap::Socket::Shared::isOpen(this=0x0000000130204348) at socket.cpp:163:36
frame #2: 0x000000010000d0a4 hello_debugger`dap::ContentReader::isOpen(this=0x00000001302043f0) at content_stream.cpp:40:27
frame #3: 0x0000000100052738 hello_debugger`(anonymous namespace)::Impl::startProcessingMessages(this=0x00000001302047a8)> const&)::'lambda'()::operator()() const at session.cpp:87:21
error
0 '\0'
ETA: I wouldn't say getsockopt() is returning an incorrect value, it just seems that the implementation in cppdap is not robust enough. From my quick researching, a clean closed TCP socket (one that received FIN) will not be in an error state (ie. SO_ERROR sets error to 0). When the connection is closed, the current blocking recv() call returns -1, and any subsequent calls will return 0.
The implementation of read()completely swallows the error state of recv() returning -1, and just returns to the caller the fact that "no data has been read":
Activity
KevinEady commentedon Jun 27, 2025
It look like it stems from
errored(SOCKET s)not returning the correct value fromgetsockopt:cppdap/src/socket.cpp
Lines 81 to 84 in 6464cd7
ETA: I wouldn't say
getsockopt()is returning an incorrect value, it just seems that the implementation in cppdap is not robust enough. From my quick researching, a clean closed TCP socket (one that receivedFIN) will not be in an error state (ie.SO_ERRORsetserrorto0). When the connection is closed, the current blockingrecv()call returns-1, and any subsequent calls will return0.cppdap/src/socket.cpp
Lines 203 to 211 in 6464cd7
The implementation of
read()completely swallows the error state ofrecv()returning-1, and just returns to the caller the fact that "no data has been read":cppdap/src/socket.cpp
Lines 203 to 211 in 6464cd7
KevinEady commentedon Jun 27, 2025
Modifying
read():Seems to solve the problem... is this an acceptable solution? If so, I can create a pull request.