#765·gnet

Shutdown returns from poller without unblocking Enroll, and failed Enroll leaks duplicated socket fd

Author: hazyhaarCreated Sep 24, 2026Updated Sep 24, 2026

Summary

Two related lifecycle issues affect Client.EnrollContext / EventLoop.enroll during shutdown or failed registration:

  1. Poller shutdown drops tasks without unblocking Enroll: Polling returns on ErrEngineShutdown before clearing wakeupCall and before draining the queued tasks. A subsequent Trigger treats the failed compare-and-swap as success, and Enroll blocks indefinitely on <-connOpened, which is never closed. Furthermore, inShutdown was only stored after waiting for event loops to close.

  2. Duplicated socket file descriptor leak: socket.Dup hands ownership of the duplicated descriptor to Enroll, but error returns before poller registration and eventloop.close on an unopened connection drop the descriptor without calling unix.Close. This leads to file descriptor exhaustion (EMFILE).

Proposed Fix

  • Publish inShutdown before waking pollers, fail Trigger once Polling has retired, and await Done() channel.
  • Manage duplicated file descriptor with defer until registration takes ownership, and close via releaseUnopened if unopened.

A complete tested fix is submitted concurrently in a Pull Request.