Connection aborted by peer
Production Risk
Non-fatal in server accept loops; implement retry.
A subclass of ConnectionError (errno ECONNABORTED) raised when a connection is aborted by the peer — typically when a server receives a TCP RST from a client that disconnected before the server accepted the connection.
- 1TCP client disconnected immediately after the three-way handshake
- 2Server called accept() on a connection that was already aborted
- 3Network hardware aborted the connection
Server accept() on a connection that the client already dropped.
import socket
server = socket.socket()
server.bind(('', 8080))
server.listen(5)
try:
conn, addr = server.accept()
except ConnectionAbortedError:
pass # Client disconnected before acceptexpected output
ConnectionAbortedError: [Errno 103] Software caused connection abort
Fix
Retry accept() on ConnectionAbortedError
WHEN Writing a server accept loop
import socket
server = socket.socket()
server.bind(('', 8080))
server.listen(10)
while True:
try:
conn, addr = server.accept()
handle_client(conn)
except ConnectionAbortedError:
continue # Client aborted — retryWhy this works
ConnectionAbortedError in accept() means one client dropped out; the server socket is still valid — just retry.
import socket
server = socket.socket()
server.bind(("", 8080))
server.listen(5)
conn, addr = server.accept() # ConnectionAbortedError if client droppedwhile True:
try:
conn, addr = server.accept()
except ConnectionAbortedError:
continue # client dropped — retryimport selectors, socket sel = selectors.DefaultSelector() sel.register(server, selectors.EVENT_READ) # Only call accept() when socket is ready
✕ Treat ConnectionAbortedError in accept() as a fatal server error
Only one client connection was aborted; the listening socket is still valid.
Python Docs — Built-in Exceptions
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev