Skip to content
uencoder

SO_REUSEADDR

SO_REUSEADDR lets a socket bind to an address stuck in TIME_WAIT, letting a restarted server reclaim its port immediately.

Purpose

It avoids "Address already in use" on server restart by allowing immediate rebinding of a just-closed port.

Mechanism

Once set, bind() accepts local addresses whose connections are still in TIME_WAIT. TIME_WAIT lasts 2MSL (roughly 60-120 s), which you would otherwise have to wait out. Note the distinction from SO_REUSEPORT.

Use cases

  • Fast server restarts
  • Port reuse
  • Development and debugging

Related tools

References