OpenSSL.SSL.SysCallError: (10054, 'WSAECONNRESET')

This error is being thrown after making around 1500 successful quests to an api of 3200 total.

The api returns a 204 of No content and I check for that status code and add it to another list to retry later.

What are the possible reasons for r = requests.put("https://my.api/update") might toss this error?


I suspect this will be fixed when https://github.com/shazow/urllib3/pull/729#issuecomment-151929787 is merged and urllib3 is updated for the next requests release.


```
Traceback (most recent call last):
  File "..\requests-2.8.1-py2.7.egg\requests\api.py", line 122, in put
    return request('put', url, data=data, **kwargs)
  File "..\requests-2.8.1-py2.7.egg\requests\api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "..\requests-2.8.1-py2.7.egg\requests\sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "..\requests-2.8.1-py2.7.egg\requests\sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "..\requests-2.8.1-py2.7.egg\requests\adapters.py", line 370, in send
    timeout=timeout
  File "..\requests-2.8.1-py2.7.egg\requests\packages\urllib3\connectionpool.py", line 559, in urlopen
    body=body, headers=headers)
  File "..\requests-2.8.1-py2.7.egg\requests\packages\urllib3\connectionpool.py", line 376, in _make_request
    httplib_response = conn.getresponse(buffering=True)
  File "C:\Python27\ArcGIS10.3\lib\httplib.py", line 1067, in getresponse
    response.begin()
  File "C:\Python27\ArcGIS10.3\lib\httplib.py", line 409, in begin
    version, status, reason = self._read_status()
  File "C:\Python27\ArcGIS10.3\lib\httplib.py", line 365, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "C:\Python27\ArcGIS10.3\lib\socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
  File "..\requests-2.8.1-py2.7.egg\requests\packages\urllib3\contrib\pyopenssl.py", line 179, in recv
    data = self.connection.recv(*args, **kwargs)
  File "..\OpenSSL\SSL.py", line 1320, in recv
    self._raise_ssl_error(self._ssl, result)
  File "..\OpenSSL\SSL.py", line 1178, in _raise_ssl_error
    raise SysCallError(errno, errorcode.get(errno))
SysCallError: (10054, 'WSAECONNRESET')
```


This is actually a new bug, it's not the same as shazow/urllib3#729. urllib3 should be wrapping `SysCallError` in this case. @steveoh, can you raise this issue on urllib3?


So @Lukasa, how does that little change affect us here? How will requests act differently with the wrapped error?


@steveoh urllib3 should now see this as a standard socket error, and so wrap it, and requests will then wrap _that_. I'd expect a standard requests error to be seen.


@Lukasa Any idea why the socket is throwing the error in the first place?


@steveoh Sure. The error is clear if you happen to speak Windows error codes (and I do). ;)

The error code WSAECONNRESET means that the TCP connection was forcefully closed by the remote peer. This means something about this request the server doesn't like. It'd be interesting if you checked what the state of your system was when it happened so you could see what the request was.


It happens during a long request. My suspicion is a timeout is reached.


A server should not have a timeout like that: generally speaking, if the connection is still active there's no need to time it out.


@Lukasa could it be that there's a load balancer terminating TLS and that's timing out the connection?


Certainly possible.