Skip to content

Fix insufficient resources error handling - #819

Open
ZihaoFU245 wants to merge 1 commit into
klzgrad:masterfrom
ZihaoFU245:fix-resource-exhaust
Open

Fix insufficient resources error handling#819
ZihaoFU245 wants to merge 1 commit into
klzgrad:masterfrom
ZihaoFU245:fix-resource-exhaust

Conversation

@ZihaoFU245

Copy link
Copy Markdown
Contributor

When naive DoAccept failed on ERR_INSUFFICIENT_RESOURCES, rv is passed to DoAcceptComplete, if rv is not OK, this function sets next state to DoAccept again, when naive reaches system wide file discriptor limits, and a pending CONNECT in queue, naive will be trapped in an infinite busy spinning loop and can not recover as resources are not reclaimed.

Trigger requirements:

  1. Naive has reached its per-process file descriptor limit or the system-wide descriptor limit.
  2. A new TCP connection is waiting in the listening socket’s accept queue

The patch schedules a 1 second retry, and returns ERR_IO_PENDING to exit DoLoop from busy spinning, and calls OnIOComplete to reclaim resources, so naive can recover from this trap.

This issue is founded when testing naive with #818 , DNS on UDP can consume resources very quickly, and would trigger this issue. Though on CONNECT (TCP) this case is very rare it could happen.

@ZihaoFU245

Copy link
Copy Markdown
Contributor Author

The triggering can be done by open many TCP connections to the socks listener. keep the connections open/stall, each conenciton will let naive consume a discriptor, naive reaches fd max, accept returns insufficient resoruces, naive is trapped.

Comment thread src/net/tools/naive/naive_proxy.cc Outdated
When naive DoAccept failed on ERR_INSUFFICIENT_RESOURCES, rv is passed
to DoAcceptComplete, if rv is not OK, this function sets next state to
DoAccept again, when naive reaches system wide file discriptor limits,
and a pending CONNECT in queue, naive will be trapped in an infinite
busy spinning loop and can not recover as resources are not reclaimed.
@ZihaoFU245
ZihaoFU245 force-pushed the fix-resource-exhaust branch from 70b8646 to e6d6e19 Compare July 21, 2026 18:01
@ZihaoFU245
ZihaoFU245 requested a review from klzgrad July 21, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants