Demian Brecht added the comment:

Hi Martin,

Thanks for the example code. I'm not sure whether or not this was your 
intention, but your example demonstrates a misbehaving client, one that seems 
to expect a persistent connection from a non-persistent server. TCPServer will 
only serve a single request and will shutdown and close the socket once the 
response has been written.

The reason that you're seeing different responses sometimes (varying between 
BadStatusLine and BrokenPipeError) is because of an understandable race 
condition between the client sending the requests and the server fully shutting 
down the socket and the client receiving FIN.

After digging into this, I'm not sure that there is a better way of handling 
this case. This exception can occur whether the client has issued a request 
prior to cleaning up and is expecting a response, or the server is simply 
misbehaving and sends an invalid status line (i.e. change your response code to 
an empty string to see what I mean).

I'll do some further digging, but I don't believe that there's really a good 
way to determine whether the BadStatusLine is due to a misbehaving server 
(sending a non-conforming response) or a closed socket. Considering that the 
client potentially has no way of knowing whether or not a server socket has 
been closed (in the case of TCPServer, it does a SHUT_WR), I think that 
BadStatusLine may be the appropriate exception to use here and the resulting 
action would have to be left up to the client implementation, such as in 
xmlrpc.client.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue3566>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to