-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
send
== 0: how to wait for socket to drain?
#320
Comments
Hmm, this would possibly require dropping down to |
@bscottm Are you able to produce a minimal test case for this failure? |
@eborden: I'll see what I can craft... Probably the best test case would be to take the Receiver side is a bit trickier because the receiver's call to /cc @mvoidex |
What about this? sendAll :: Socket -- ^ Connected socket
-> ByteString -- ^ Data to send
-> IO ()
sendAll sock bs
| B.null bs = return ()
| otherwise = do
sent <- send sock bs
if sent == 0 then do
threadWaitWrite $ fromIntegral $ sockFd sock
sendAll sock bs
else if sent > 0 then
sendAll sock (B.drop sent bs)
else
return () |
I have not been able to successfully reproduce the |
@bscottm Thanks! |
|
I did many |
fixed via #321 |
I ran into this particular problem in @mvoidex's
hsdev
server while tracking down whyhsdev
would send incomplete responses. I was able to track the problem down to a reimplementation ofsendAll
:The subtle bug in this code is the
send > 0
:send
can return 0 because the OS is waiting for a buffer to drain and the underlying descriptors are in non-blocking mode (GHC runtime "feature".)One way around the
send == 0
issue is to callControl.Concurrent.threadDelay
. Optimally, you'd really want to callControl.Concurrent.threadWaitWrite
, but you can't because converting the socket to a file descriptor is a one way process.Is there a way to call
threadWaitWrite
without converting the socket to a descriptor?The text was updated successfully, but these errors were encountered: