By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,032 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

Minimizing Connection reset by peer exceptions

P: n/a
This may be more of a socket question than a python question; not sure.

Using this code to instantiate/connect/set options
connectionHandle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
errorStatus = connectionHandle.connect_ex((ipAddress, port))
connectionHandle.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO,
60000)

Using this code to send:
retSendAll = connectionHandle.sendall(messageToHost)

Followed by this code to recv:
bufferSize = 500000
responseBuffer = connectionHandle.recv(bufferSize)

Occasionally (perhaps 5% of the time) the following exception gets
raised:

(10054, 'Connection reset by peer')
Are there any changes I can make to the code above to eliminate the
10054 errors or to reduce the probability of encountering the 10054
error? Are there any settings that make the 'Connection reset by
peer' condition less likely?

Other posts on this subject seem to suggest that this can only be
handled by:
1) detecting the 10054 error
2) issuing a message explaining the 'connection reset' condition
followed by something along the lines of 'try again later'.

Oct 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

mi************@yahoo.com wrote:
Occasionally (perhaps 5% of the time) the following exception gets
raised:

(10054, 'Connection reset by peer')


Generally this just means the connection has closed through some
unusual means, perhaps by being turned off, or a network cable being
unplugged, or a timeout along the way, etc. 5% is a high figure, but
perhaps you connect to hosts that are unreliable for some reason.

You don't have control over this really; just make sure you handle the
exception. Such is life, when dealing with networking.

--
Ben Sizer

Oct 20 '05 #2

P: n/a
Ben Sizer wrote:
mi************@yahoo.com wrote:

Occasionally (perhaps 5% of the time) the following exception gets
raised:

(10054, 'Connection reset by peer')

Generally this just means the connection has closed through some
unusual means, perhaps by being turned off, or a network cable being
unplugged, or a timeout along the way, etc. 5% is a high figure, but
perhaps you connect to hosts that are unreliable for some reason.

You don't have control over this really; just make sure you handle the
exception. Such is life, when dealing with networking.

Do note, though, that if you aren't using some means (threading,
forking, etc) of handling the connections asynchronously then your
server will normally only queue a very limited number of connections
(usually 5 at most).

So if your service takes a while to run then it's possible that
connection requests will be rejected when the queue is full, which might
*possibly* result in the error you are seeing.

Feel free to ignore this if you only have one client at a time.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 20 '05 #3

P: n/a

Steve Holden wrote:
Do note, though, that if you aren't using some means (threading,
forking, etc) of handling the connections asynchronously then your
server will normally only queue a very limited number of connections
(usually 5 at most).


The example given by the original poster seemed to be a client (using
connect_ex) rather than a server, so I think this would only be an
issue if the code was connecting to the same host repeatedly in quick
succession.

--
Ben Sizer

Oct 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.