Diagnosing socket "Connection reset by peer"

Jorgen Grahn grahn+nntp at snipabacken.se
Wed May 22 15:54:05 EDT 2013


On Wed, 2013-05-22, Matt Jones wrote:
> On Wed, May 22, 2013 at 3:46 AM, loial <jldunn2000 at gmail.com> wrote:
>
>> I have a sockets client that is connecting to a printer and occassionally
>> getting the error "104 Connection reset by peer"
>>
>> I have not been able to diagnose what is causing this. Is there any
>> additional traceing I can do(either within my python code or on the
>> network) to establish what is causing this error?
>>
>> Currently I am simply trapping socket.erruor
>>
>> Python version is 2.6

> This typically indicates that the "peer" at the other end of the tcp
> connection severed the session without the typical FIN packet.

I.e. by sending a RST (reset) instead.  Yes, that's what "Connection
reset by peer" means.  I don't think there are any other causes for
this signal.

A server application can cause a reset explicitly, or if it crashes
the OS will send one for it, as part of the resource cleanup.

Also, if you're behind a cheap NATing gateway, I think it may send
fake RSTs if it has lost track of the TCP session.

> If you're
> treating the printer as a "blackbox" then there really isn't anything you
> can do here except catch the exception and attempt to reconnect.

Yes.  Note that there *may* be some uncertainty re: "did the printer
process the last request before the reset or not?" E.g. I wouldn't
endlessly retry printing a 100-page document in that case.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .



More information about the Python-list mailing list