21

If I am coding on Flask, then I sometimes get this error:

Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\lib\SocketServer.py", line 640, in __init__
    self.finish()
  File "C:\Python27\lib\SocketServer.py", line 693, in finish
    self.wfile.flush()
  File "C:\Python27\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] ��������� �� ����� ����-

Any ideas why this would happen (win8 x64, python27 x32)?

Matt Way
  • 32,319
  • 10
  • 79
  • 85
Patrick Burns
  • 1,763
  • 6
  • 21
  • 35

7 Answers7

27

From the Windows Sockets Error Codes list:

WSAECONNABORTED 10053
Software caused connection abort.
An established connection was aborted by the software in your host computer, possibly due to a data transmission time-out or protocol error.

There was a timeout or other network-level error. This is your operating system closing the socket, nothing to do with Python or Flask, really.

It could be the remote browser stopped responding, the network connection died, or a firewall closed the connection because it was open too long, or any other number of reasons.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • but i havent firewolls, anti virus and etc. – Patrick Burns Jul 25 '13 at 13:14
  • 4
    I was listing *some* of the possibilities. – Martijn Pieters Jul 25 '13 at 13:15
  • 5
    That is impossible for us to tell. You didn't include any information as to what you were doing at the time, your platform, your network setup, your client, etc. We are stuck with giving you generic information about the error code. – Martijn Pieters Jul 25 '13 at 13:28
  • 1
    @MartijnPieters I was wondering the same thing. You might want to check this post:http://stackoverflow.com/a/20421867/2290820 – user2290820 Dec 06 '13 at 11:23
  • check your database connection – vipin Aug 29 '14 at 12:25
  • @vipin: the traceback in the question has **nothing to do** with a database connection. – Martijn Pieters Aug 29 '14 at 12:26
  • i had occured same error and it was because of my database connectivity and when i restarted my database everything worked fine – vipin Aug 29 '14 at 12:28
  • 1
    @vipin: you can certainly get socket errors too when your database socket has been closed, but in the case of the OP the traceback is due to the HTTP client having closed the connection. – Martijn Pieters Aug 29 '14 at 12:33
  • Martijn, would you happen to know how to stop Flask from crashing whenever browser closes the connection? Because Flask app keeps dying whenever I navigate away from a page that is still loading. – tonysepia Oct 25 '16 at 15:33
  • @TonySepia: that's altogether too little information for me to debug, nor are comments the place for that. Perhaps you can create a [MCVE] and post a new question? – Martijn Pieters Oct 25 '16 at 15:38
  • @MartijnPieters, here you are http://stackoverflow.com/questions/40247025/flask-socket-error-errno-10053-an-established-connection-was-aborted-by-the – tonysepia Oct 25 '16 at 18:22
9

Hello, This is an issue with the Python 2 implementation of the SocketServer module, it is not present in Python 3 (where the server keeps on serving).

Your have 3 options:

Don't use the built-in server for production systems (it is a development server after all). Use a proper WSGI server like gunicorn or uWSGI.

Enable threaded mode with app.run(threaded=True); the thread dies but a new one is created for future requests,

Upgrade to Python 3.

So whenever there is error like

error: [Errno 10053] An established connection was aborted by the software in your host machine

Server would be restarted if you have done like app.run(threaded=True).

Keyur
  • 91
  • 1
  • 1
5

I recently ran into this error message while trying to use Flask to serve audio files. I get this error message whenever the client closes the stream before the end of the stream. Flask continues to try to write data to the stream, but since the underlying socket has been disconnected, it can't. This isn't actually an error per se, but rather a message informing you that the connection to the client has been closed before Flask finished writing data to the stream.

Nop
  • 188
  • 2
  • 9
4

I have just experienced exactly the same problem. Contrary to the most upvoted answer, the issue has a lot to do with Python and Flask, and it is not a Windows issue. Very easy to reproduce:

  • Click on a link within a flask application and then navigate to another page whilst the first one is still loading. Error appears every time and application crashes (needs restarting)
  • The issue never happens if I allow the server to return the page completely.

Also, this has never happened with bottle micro-framework, for example.

If I find out how to solve the problem I will let you know

tonysepia
  • 3,340
  • 3
  • 27
  • 45
  • 1
    As promised, here is the solution: http://stackoverflow.com/questions/40247025/flask-socket-error-errno-10053-an-established-connection-was-aborted-by-the – tonysepia Apr 14 '17 at 09:43
2

I met this problem when reading response from a web server. For my case, the problem was I close the socket connection too early that it broke the communications. So I sleep some seconds before receiving data and then close the socket connection.

time.sleep(10)
data = s.recv(1024)
s.close()

It works for me.

Dabay Wang
  • 71
  • 2
2

This error can occur regardless of Flask, Python 2, Python 3, or HTTP -- it can occur simply at the socket level and it will depend heavily on your exact situation.

As an example, my application uses an Ethernet device/appliance that uses raw sockets for command and control and I am using the create_connection method in the socket module. I would consistently get "Errno 10053" after trying to send a message after a period of traffic inactivity. Timing tests showed that this error would occur after trying to send a message after four minutes of inactivity. The following page indicates a 240 second = 4min timeout:

https://support.microsoft.com/en-us/help/170359/how-to-modify-the-tcp-ip-maximum-retransmission-time-out

The solution in my scenario was to ensure that messages to the device did not span more than four minutes. I simply send a small request message to the device every 60sec to avoid the 10053 error -- this acts as a protocol-level "keep-alive" (unrelated to TCP keepalive). In this scenario, perhaps the issue is specific to the Ethernet device and the way they've implemented TCP. Nonetheless, a protocol-level "keep-alive" may be a viable option in many cases.

rob_7cc
  • 797
  • 6
  • 16
1

It's a PIPE error, which occurs if the server responds to a request and the client has already closed the connection. Browsers do that sometimes depending on usage. You can ignore those, web servers suited for production certainly will.

jayant singh
  • 929
  • 12
  • 17