Skip to content

Commit

Permalink
feat(server): add tcp_sleep_on_accept_errors builder method
Browse files Browse the repository at this point in the history
This method allows to set the value of the `sleep_on_errors` option for
accepted connections using the builder.

Closes #1713
  • Loading branch information
starsheriff authored and seanmonstar committed Nov 28, 2018
1 parent 73345be commit a6fff13
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,25 @@ impl<E> Builder<AddrIncoming, E> {
self.incoming.set_nodelay(enabled);
self
}

/// Set whether to sleep on accept errors.
///
/// A possible scenario is that the process has hit the max open files
/// allowed, and so trying to accept a new connection will fail with
/// EMFILE. In some cases, it's preferable to just wait for some time, if
/// the application will likely close some files (or connections), and try
/// to accept the connection again. If this option is true, the error will
/// be logged at the error level, since it is still a big deal, and then
/// the listener will sleep for 1 second.
///
/// In other cases, hitting the max open files should be treat similarly
/// to being out-of-memory, and simply error (and shutdown). Setting this
/// option to false will allow that.
///
/// For more details see [`AddrIncoming::set_sleep_on_errors`]
pub fn tcp_sleep_on_accept_errors(mut self, val: bool) -> Self {
self.incoming.set_sleep_on_errors(val);
self
}
}

0 comments on commit a6fff13

Please sign in to comment.