Minimizing Connection reset by peer exceptions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mirandacascade@yahoo.com

    #1

    Minimizing Connection reset by peer exceptions

    This may be more of a socket question than a python question; not sure.

    Using this code to instantiate/connect/set options
    connectionHandl e = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
    errorStatus = connectionHandl e.connect_ex((i pAddress, port))
    connectionHandl e.setsockopt(so cket.SOL_SOCKET , socket.SO_RCVTI MEO,
    60000)

    Using this code to send:
    retSendAll = connectionHandl e.sendall(messa geToHost)

    Followed by this code to recv:
    bufferSize = 500000
    responseBuffer = connectionHandl e.recv(bufferSi ze)

    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'.

  • Ben Sizer

    #2
    Re: Minimizing Connection reset by peer exceptions


    mirandacascade@ yahoo.com wrote:
    [color=blue]
    > Occasionally (perhaps 5% of the time) the following exception gets
    > raised:
    >
    > (10054, 'Connection reset by peer')[/color]

    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

    Comment

    • Steve Holden

      #3
      Re: Minimizing Connection reset by peer exceptions

      Ben Sizer wrote:[color=blue]
      > mirandacascade@ yahoo.com wrote:
      >
      >[color=green]
      >>Occasionall y (perhaps 5% of the time) the following exception gets
      >>raised:
      >>
      >>(10054, 'Connection reset by peer')[/color]
      >
      >
      > 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.
      >[/color]
      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/

      Comment

      • Ben Sizer

        #4
        Re: Minimizing Connection reset by peer exceptions


        Steve Holden wrote:
        [color=blue]
        > 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).[/color]

        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

        Comment

        Working...