Conversation
|
Hi! Thank you for your submit. So to understand it correctly, you're saying that you have to call select between the accept and the recv? |
|
Hi, yes, that's what I observed, select between accept and recv fixed it. If the socket was intended to be blocking, it wasn't in my case, as far as I could tell. |
|
Then again, MicroProfileSetNonBlocking(S.ListenerSocket, 1); is being called, so maybe it's supposed to be non-blocking after all? |
|
I think this is where it is platform dependent. I'm pretty sure I remember window always creates sockets in Blocking mode. |
|
This is my understanding as well:
The ListenerSocket is created as non-blocking here: Then
|
|
Hi. Can you try this code, and see if this fixes your issue? The intent of the code here is that the socket should be blocking, but it seems like it isn't. |
|
Confirming that your fix also works. |
|
Hello again Jonas, I re-tested your fix on Windows (no Wine or Docker), and I found that, with a small probability, it causes my program to hang for about 80 seconds. The callstack during the hang is: ntdll.dll!NtWaitForSingleObject() I recorded a video of the MicroProfile page during this wait: Interestingly, if I refresh the MicroProfile page during the hang, it connects immediately, which seems like a temporary workaround. The repro rate is fairly low, but I noticed it’s more likely to get stuck if my program isn’t collecting much profiling data at the time I try to open the connection. Also, I see the same blocking behavior with both your fix and my original attempt, the only difference is that in my version it blocks in select() instead of recv(). |
This fixes an issue where recv() is called on a non-blocking socket immediately after accept() before it's ready for reading, returns -1 and the connection is closed.
I found this when I was trying to profile a Windows executable running in Wine on Linux in a Docker container in Kubernetes on AWS. I tried to connect to it from a local web browser via kubectl port-forward and it kept closing the connection 100% of the times. This was the only setup I was able to reproduce it with. I believe the kubectl port-forward was the main trigger for the issue because I didn't observe it when connecting from inside the Docker container.