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 }}
Repository navigation
Incomplete socket send with fast writer and slow reader #610
This issue does not reproduce for me if I run curl.exe in Windows.
It also doesn't reproduce for me if I run python -m SimpleHTTPServer in Windows, and curl in WSL.
It also doesn't reproduce for me if I redirect curl's stdout; for example, curl http://localhost:8000/big.dat | wc -c.
I'm mildly perturbed that curl is attempting to push its error message through the kernel one byte at a time. But that's presumably after the actual failure has occurred.
Adam Seering (@aseering) - Thanks for reporting the issue and the repro steps. I was able to reproduce this issue and I have an understanding of the bug.
I'm not sure if the issue I am experiencing is related but I think it is.
I get constant "net::ERR_CONTENT_LENGTH_MISMATCH" errors from Chrome when I try to visit my uWSGI HTTP server. When using Flask as webserver, I get frequent "net::ERR_CONNECTION_RESET" (in the Flask stacktrace I get some Broken Pipe errors, I will attach them soon. I don't always get these Broken Pipe stack traces). This same app works fine on a virtual machine for both uWSGI and Flask.
If you need any more information, please do ask.
Edit: Client Chrome is not running from WSL.
Edit 2: I'm being silly. Let me include some information. Windows build: Version 1607 (OS Build 14946) Ubuntu version: 16.04 Xenial (apt-get dist-upgrade from 14.04) uWSGI version: 2.0.3 uWSGI cmdline args: "--http 127.0.0.1:5000" Flask version: 0.10.1
Edit 3: (Running the Flask webserver here) When trying to access my app from Firefox running on WSL itself, the file just doesn't fully transfer over (JS in my case), causing the script to fail. So, it doesn't matter whether the client is Windows or WSL..
When trying to fetch the file with curl (CURL v7.47.0 on WSL) I get
(18) transfer closed with 524925 bytes remaining to read
xbytez@i5-2500K:~$
When trying to fetch the same on Windows (CURL v7.49.1 on Windows) I get
curl: (56) Recv failure: Connection was reset
C:\Users\xBytez>
Edit 4:
The promised stacktrace
Exception happened during processing of request from ('127.0.0.1', 19431)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 290, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 318, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 654, in __init__
self.finish()
File "/usr/lib/python2.7/SocketServer.py", line 713, in finish
self.wfile.close()
File "/usr/lib/python2.7/socket.py", line 283, in close
self.flush()
File "/usr/lib/python2.7/socket.py", line 307, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
Sunil Muthuswamy (@sunilmut) -- you mentioned a little while back that you have a repro for this; just wondering where it is on your priority list?
There's this ticket and there's #616; if you keep tracing there are about a dozen tickets that refer to those two; etc. It would be great to hear something from y'all about what your plans are for this collection of issues.
FYI -- this still reproduces on build 14955 and Ubuntu 16.04.
Interestingly, during this download, CPU usage on the machine goes up a lot. But that usage doesn't show up in top running in WSL; it's not assigned to either Python or cURL. If I open up Task Manager, I see Console Window Host pegging a CPU core. Neither application is writing anything to stdout when this increased CPU utilization occurs.
Adam Seering (@aseering) - Thanks for reviving this thread again. I was out for couple of weeks and so the delay in the response. I will take this up immediately, since I agree that this could be manifesting in many different forms. I will post back once I have something.
Thanks you so much for the update. Once this is fixed I can actually move my dev environment fully to WSL! Thanks to you too Adam Seering (@aseering) for your continous support for WSL, you're everywhere ;).
Adam Seering (@aseering) - So, I have root caused the problem. The way the repro is setup, the server (python) side after sending the last byte, calls shutdown and closes the socket. Watching the data transfer under the debugger, it appears that whenever the socket is being closed by python, invariably, there is pending data to be sent. When there is pending data in the socket (with linger disabled), WSL closes the socket in the background. The way the background logic works is that it will wait for the last byte to be sent or a timeout, whichever comes first. After that it will force close the socket. In this case, we are not hitting the timeout and WSL force closes the socket after sending the last byte. Force closing the socket causes an abortive disconnect, which disregards any data that has not been received so far by the peer (i.e curl in this case).
Now, when I look at the socket man page, the line that grabs my attention is When the socket is closed as part of exit(2), it always lingers in the background. And, it makes me wonder, "how long does the socket linger in the background (maybe by trying to do a graceful disconnect) after sending the last byte, before forcefully closing the connection".
Sunil Muthuswamy (@sunilmut) -- hm, good question... As a programmer, my instinctive expectation is that there would be no simple timeout. I can't immediately find anything online that contradicts that expectation.
I would expect applications that care about such things to manage them explicitly using SO_LINGER in order to have more-granular control over the socket's exact behavior. In that case, the kernel is given an explicit timeout and should follow it.
If the client dies or otherwise goes unresponsive while the server is trying to send data, then the connection will naturally hit TCP's built-in retry-count limit and get torn down. That's true regardless of whether the server is still trying to send, but, given that the kernel buffer is of bounded size, it does guarantee that the socket will close in bounded (though very large in the worst case) time.
Basically, TCP itself guarantees that the send must still be making progress. If it's making progress, why kill it? If the answer is "because I'm worried about running out of kernel memory or ephemeral ports", then your app is dealing with high load and should be using features like SO_LINGER to carefully manage its resource usage. If it's not -- c'mon, that's like two lines of code; just go fix it :-) (Ah, the advantages of a mostly-open-source ecosystem on the design of the underlying platform...)
Basically, TCP itself guarantees that the send must still be making progress. If it's making progress, why kill it?
The primary motivation for our design decisions is compatibility.
As a programmer, my instinctive expectation is that there would be no simple timeout.
Do you have anything (link) that supports this? My searches are returning empty handed. Maybe that is what you also mean by I can't immediately find anything online that contradicts that expectation. :)
It seems that 14986 caused this problem occuring more often. I'm using gulp's http server, so this issue is more visible in the browser when loading assets (larger CSS or JS files). Before 14986 i was able to refresh browser few times until it stopped interrupting with assets download, but now it seems i can't do that anymore. Issue is more persistent. Any ideas on new build release date (+/-)?
The fix has made it to the release branch. It depends on which build they snap for the Insider release (which is not in our (WSL team's) control). If not in the upcoming Insider release build, it should definitely be in the next one after that. I don't have any more insight into the timelines/dates etc. Thanks for your patience.
This should be fixed in 15002. Please validate and let us know if the issue persists. Thanks for your patience, ALL and persistence, Adam Seering (@aseering).
Activity
aseering commentedon Jul 1, 2016
This issue does not reproduce for me if I run
curl.exein Windows.It also doesn't reproduce for me if I run
python -m SimpleHTTPServerin Windows, andcurlin WSL.It also doesn't reproduce for me if I redirect curl's stdout; for example,
curl http://localhost:8000/big.dat | wc -c.aseering commentedon Jul 1, 2016
strace on the Python server:
strace on the curl client:
I'm mildly perturbed that curl is attempting to push its error message through the kernel one byte at a time. But that's presumably after the actual failure has occurred.
sunilmut commentedon Jul 8, 2016
Adam Seering (@aseering) - Thanks for reporting the issue and the repro steps. I was able to reproduce this issue and I have an understanding of the bug.
xBytez commentedon Oct 19, 2016
I'm not sure if the issue I am experiencing is related but I think it is.
I get constant "net::ERR_CONTENT_LENGTH_MISMATCH" errors from Chrome when I try to visit my uWSGI HTTP server. When using Flask as webserver, I get frequent "net::ERR_CONNECTION_RESET" (in the Flask stacktrace I get some Broken Pipe errors, I will attach them soon. I don't always get these Broken Pipe stack traces). This same app works fine on a virtual machine for both uWSGI and Flask.
If you need any more information, please do ask.
Edit: Client Chrome is not running from WSL.
Edit 2: I'm being silly. Let me include some information.
Windows build: Version 1607 (OS Build 14946)
Ubuntu version: 16.04 Xenial (apt-get dist-upgrade from 14.04)
uWSGI version: 2.0.3
uWSGI cmdline args: "--http 127.0.0.1:5000"
Flask version: 0.10.1
Edit 3: (Running the Flask webserver here) When trying to access my app from Firefox running on WSL itself, the file just doesn't fully transfer over (JS in my case), causing the script to fail. So, it doesn't matter whether the client is Windows or WSL..
When trying to fetch the file with curl (CURL v7.47.0 on WSL) I get
When trying to fetch the same on Windows (CURL v7.49.1 on Windows) I get
Edit 4:
The promised stacktrace
aseering commentedon Oct 20, 2016
Sunil Muthuswamy (@sunilmut) -- you mentioned a little while back that you have a repro for this; just wondering where it is on your priority list?
There's this ticket and there's #616; if you keep tracing there are about a dozen tickets that refer to those two; etc. It would be great to hear something from y'all about what your plans are for this collection of issues.
aseering commentedon Oct 30, 2016
FYI -- this still reproduces on build 14955 and Ubuntu 16.04.
Interestingly, during this download, CPU usage on the machine goes up a lot. But that usage doesn't show up in
toprunning in WSL; it's not assigned to either Python or cURL. If I open up Task Manager, I see Console Window Host pegging a CPU core. Neither application is writing anything to stdout when this increased CPU utilization occurs.sunilmut commentedon Oct 31, 2016
Adam Seering (@aseering) - Thanks for reviving this thread again. I was out for couple of weeks and so the delay in the response. I will take this up immediately, since I agree that this could be manifesting in many different forms. I will post back once I have something.
xBytez commentedon Oct 31, 2016
Thanks you so much for the update. Once this is fixed I can actually move my dev environment fully to WSL! Thanks to you too Adam Seering (@aseering) for your continous support for WSL, you're everywhere ;).
sunilmut commentedon Nov 1, 2016
Adam Seering (@aseering) - So, I have root caused the problem. The way the repro is setup, the server (python) side after sending the last byte, calls shutdown and closes the socket. Watching the data transfer under the debugger, it appears that whenever the socket is being closed by python, invariably, there is pending data to be sent. When there is pending data in the socket (with linger disabled), WSL closes the socket in the background. The way the background logic works is that it will wait for the last byte to be sent or a timeout, whichever comes first. After that it will force close the socket. In this case, we are not hitting the timeout and WSL force closes the socket after sending the last byte. Force closing the socket causes an abortive disconnect, which disregards any data that has not been received so far by the peer (i.e curl in this case).
Now, when I look at the socket man page, the line that grabs my attention is
When the socket is closed as part of exit(2), it always lingers in the background.And, it makes me wonder, "how long does the socket linger in the background (maybe by trying to do a graceful disconnect) after sending the last byte, before forcefully closing the connection".aseering commentedon Nov 2, 2016
Sunil Muthuswamy (@sunilmut) -- hm, good question... As a programmer, my instinctive expectation is that there would be no simple timeout. I can't immediately find anything online that contradicts that expectation.
I would expect applications that care about such things to manage them explicitly using
SO_LINGERin order to have more-granular control over the socket's exact behavior. In that case, the kernel is given an explicit timeout and should follow it.If the client dies or otherwise goes unresponsive while the server is trying to send data, then the connection will naturally hit TCP's built-in retry-count limit and get torn down. That's true regardless of whether the server is still trying to send, but, given that the kernel buffer is of bounded size, it does guarantee that the socket will close in bounded (though very large in the worst case) time.
Basically, TCP itself guarantees that the send must still be making progress. If it's making progress, why kill it? If the answer is "because I'm worried about running out of kernel memory or ephemeral ports", then your app is dealing with high load and should be using features like
SO_LINGERto carefully manage its resource usage. If it's not -- c'mon, that's like two lines of code; just go fix it :-) (Ah, the advantages of a mostly-open-source ecosystem on the design of the underlying platform...)sunilmut commentedon Nov 2, 2016
Adam Seering (@aseering)
The primary motivation for our design decisions is compatibility.
Do you have anything (link) that supports this? My searches are returning empty handed. Maybe that is what you also mean by
I can't immediately find anything online that contradicts that expectation.:)aseering commentedon Nov 2, 2016
Yeah, I can't find any documentation regarding a timeout either (unless
SO_LINGERis used). I'm basically just trying to justify an educated guess.11 remaining items
krzysztofantczak commentedon Dec 30, 2016
It seems that 14986 caused this problem occuring more often. I'm using gulp's http server, so this issue is more visible in the browser when loading assets (larger CSS or JS files). Before 14986 i was able to refresh browser few times until it stopped interrupting with assets download, but now it seems i can't do that anymore. Issue is more persistent. Any ideas on new build release date (+/-)?
sunilmut commentedon Dec 30, 2016
The fix has made it to the release branch. It depends on which build they snap for the Insider release (which is not in our (WSL team's) control). If not in the upcoming Insider release build, it should definitely be in the next one after that. I don't have any more insight into the timelines/dates etc. Thanks for your patience.
sunilmut commentedon Jan 9, 2017
This should be fixed in 15002. Please validate and let us know if the issue persists. Thanks for your patience, ALL and persistence, Adam Seering (@aseering).
krzysztofantczak commentedon Jan 11, 2017
As for now (an hour of playing with stuff around after upgrade this morning), works perfectly ;-) Thank You!
xBytez commentedon Jan 11, 2017
Same here! I was able to run my Flask server just fine. Thank you!
sunilmut commentedon Jan 11, 2017
Krzysztof Antczak (@krzysztofantczak) & xBytez (@xBytez) - Really glad to know that things are working so far. Will keep the issue open for sometime, before closing it out.
aseering commentedon Jan 18, 2017
This is also working great for me. Thanks!
sunilmut commentedon Jan 18, 2017
Glad to know. Thanks Adam Seering (@aseering)