TCP server spins at 100% CPU when accept() fails with EMFILE

Abierto
#1,148 0 comentarios 0 reacciones 1 asignado Ver en GitHub

@itsGiaan ya está trabajando en esto.

Desde el 17/11/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

bug

Description

When a TCP server runs out of file descriptors, accept() fails with EMFILE. The pending connection stays in the listen queue, so the listening socket remains readable. Every event wait then returns immediately, accept() fails again, and the server busy-loops at 100% CPU.

Because the server loop only runs scheduled timers when the event wait returns no events, timers (ping-restart, hand-window, etc.) stall for as long as the condition lasts. The same applies to the management listener.

The default --max-clients is 1024, the same as the usual default soft RLIMIT_NOFILE on Linux. Since each TCP client uses one descriptor, plus the tun device, listeners, log and management, a TCP server with default settings hits EMFILE before reaching --max-clients.

On Linux the issue is not specific to the userspace data channel: it reproduces with DCO as well, since accepting connections and the event loop stay in userspace.

Affected platforms

Linux: reproduced, with both epoll and poll. The default limits are enough.
FreeBSD 14.5: reproduced (poll backend). The kernel also leaves the pending connection in the queue after a failed accept(), on a stock system the default descriptor limit is much higher (kern.maxfilesperproc), so it needs a lowered limit or a --max-clients close to it.
macOS: not affected, because XNU drops the pending connection when accept() fails.
Windows: not affected.

How to reproduce

Start a server with tcp-server listener, on Linux the default limits are enough (about 1000 connections are needed); a low limit such as ulimit -n 64 makes it quicker to reproduce.
Open TCP connections to the server port, without completing the handshake, until accept() fails with Too many open files.
Watch the CPU usage of the server process: it stays at 100% and the log fills with TCP: accept(...) failed: Too many open files (errno=24).

Patches are ready and will be sent to Gerrit.

Lenguaje dominante
C
Estrellas
14.8k
Forks
3.4k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de OpenVPN/openvpn

Todos los issues de OpenVPN/openvpn

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.