Skip to content

Commit a6fff13

Browse files
starsheriffseanmonstar
authored andcommitted
feat(server): add tcp_sleep_on_accept_errors builder method
This method allows to set the value of the `sleep_on_errors` option for accepted connections using the builder. Closes #1713
1 parent 73345be commit a6fff13

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/server/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,25 @@ impl<E> Builder<AddrIncoming, E> {
378378
self.incoming.set_nodelay(enabled);
379379
self
380380
}
381+
382+
/// Set whether to sleep on accept errors.
383+
///
384+
/// A possible scenario is that the process has hit the max open files
385+
/// allowed, and so trying to accept a new connection will fail with
386+
/// EMFILE. In some cases, it's preferable to just wait for some time, if
387+
/// the application will likely close some files (or connections), and try
388+
/// to accept the connection again. If this option is true, the error will
389+
/// be logged at the error level, since it is still a big deal, and then
390+
/// the listener will sleep for 1 second.
391+
///
392+
/// In other cases, hitting the max open files should be treat similarly
393+
/// to being out-of-memory, and simply error (and shutdown). Setting this
394+
/// option to false will allow that.
395+
///
396+
/// For more details see [`AddrIncoming::set_sleep_on_errors`]
397+
pub fn tcp_sleep_on_accept_errors(mut self, val: bool) -> Self {
398+
self.incoming.set_sleep_on_errors(val);
399+
self
400+
}
381401
}
382402

0 commit comments

Comments
 (0)