This repository has been archived by the owner. It is now read-only.

unix: reimplement EMFILE trick #315

Closed
bnoordhuis opened this Issue Feb 18, 2012 · 2 comments

Comments

Projects
None yet
2 participants
@bnoordhuis
Contributor

bnoordhuis commented Feb 18, 2012

Stash away an open file descriptor. When EMFILE is returned by e.g. accept(), close the spare and retry the operation, then close the new file descriptor. (Note: not foolproof in multi-threaded environments.)

This is good because it signals to peers that we're overloaded / stops connections from rotting away in the listen backlog. It also mitigates issues like joyent/node#2529.

@ghost ghost assigned bnoordhuis Feb 18, 2012

@dvv

This comment has been minimized.

Show comment Hide comment
@dvv

dvv Mar 27, 2012

Contributor

+1

Contributor

dvv commented Mar 27, 2012

+1

bnoordhuis added a commit that referenced this issue Sep 10, 2012

unix: reimplement accept() EMFILE trick
Implement a best effort approach to mitigating accept() EMFILE errors.

We have a spare file descriptor stashed away that we close to get below
the EMFILE limit. Next, we accept all pending connections and close them
immediately to signal the clients that we're overloaded - and we are, but
we still keep on trucking.

There is one caveat: it's not reliable in a multi-threaded environment.
The file descriptor limit is per process. Our party trick fails if another
thread opens a file or creates a socket in the time window between us
calling close() and accept().

Fixes #315.
@bnoordhuis

This comment has been minimized.

Show comment Hide comment
@bnoordhuis

bnoordhuis Sep 10, 2012

Contributor

Fixed in 4f5c8da.

Contributor

bnoordhuis commented Sep 10, 2012

Fixed in 4f5c8da.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.