This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author demian.brecht
Recipients Yuri.Bochkarev, agriffis, alanjds, amak, cananian, demian.brecht, gregory.p.smith, icordasc, jcea, jhylton, martin.panter, mhammond, orsenthil, r.david.murray
Date 2015-01-19.16:34:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1421685277.85.0.953193363767.issue3566@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-01-19 16:34:37demian.brechtsetrecipients: + demian.brecht, jhylton, mhammond, gregory.p.smith, jcea, orsenthil, amak, cananian, r.david.murray, alanjds, agriffis, martin.panter, icordasc, Yuri.Bochkarev
2015-01-19 16:34:37demian.brechtsetmessageid: <1421685277.85.0.953193363767.issue3566@psf.upfronthosting.co.za>
2015-01-19 16:34:37demian.brechtlinkissue3566 messages
2015-01-19 16:34:37demian.brechtcreate