OSError: Address Already in Use

OSError: [Errno 98] Address already in use

Quick Answer

Another process is listening on the same port. Find and stop it, use a different port, or set SO_REUSEADDR.

Why This Happens

When a server binds to a port, the OS reserves it exclusively. If a previous instance is still running or the port is in TIME_WAIT state, binding fails.

The Problem

import socket
s = socket.socket()
s.bind(('0.0.0.0', 8000))

The Fix

import socket
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('0.0.0.0', 8000))

Step-by-Step Fix

  1. 1

    Find the process

    Run lsof -i :PORT to find what is using the port.

  2. 2

    Set SO_REUSEADDR

    Allow port reuse with setsockopt before binding.

  3. 3

    Use a different port

    Change to a different port number.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free