ConnectionAbortedError
PythonERRORNotableConnection ErrorHIGH confidence

Connection aborted by peer

Production Risk

Non-fatal in server accept loops; implement retry.

What this means

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.

Why it happens
  1. 1TCP client disconnected immediately after the three-way handshake
  2. 2Server called accept() on a connection that was already aborted
  3. 3Network hardware aborted the connection
How to reproduce

Server accept() on a connection that the client already dropped.

trigger — this will error
trigger — this will error
import socket
server = socket.socket()
server.bind(('', 8080))
server.listen(5)
try:
    conn, addr = server.accept()
except ConnectionAbortedError:
    pass  # Client disconnected before accept

expected output

ConnectionAbortedError: [Errno 103] Software caused connection abort

Fix

Retry accept() on ConnectionAbortedError

WHEN Writing a server accept loop

Retry accept() on ConnectionAbortedError
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 — retry

Why this works

ConnectionAbortedError in accept() means one client dropped out; the server socket is still valid — just retry.

Code examples
Triggerpython
import socket
server = socket.socket()
server.bind(("", 8080))
server.listen(5)
conn, addr = server.accept()  # ConnectionAbortedError if client dropped
Handle in accept looppython
while True:
    try:
        conn, addr = server.accept()
    except ConnectionAbortedError:
        continue  # client dropped — retry
Avoid with non-blocking acceptpython
import selectors, socket
sel = selectors.DefaultSelector()
sel.register(server, selectors.EVENT_READ)
# Only call accept() when socket is ready
What not to do

Treat ConnectionAbortedError in accept() as a fatal server error

Only one client connection was aborted; the listening socket is still valid.

Same error in other languages
Sources
Official documentation ↗

Python Docs — Built-in Exceptions

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Python errors