Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tk_listen to absorb errors on the TcpListener #402

Merged
merged 3 commits into from
Aug 8, 2018

Conversation

tomaka
Copy link
Member

@tomaka tomaka commented Aug 7, 2018

The documentation of TcpListener suggests doing what this PR does.
The TcpListener can sometimes produce an error which would just close the listener.

I think handling this directly in the TCP transport is the right location. There might be valid reasons why a listener produces an error, therefore the upper layers should continue to drop the listener if an error happens.

@ghost ghost assigned tomaka Aug 7, 2018
@ghost ghost added the in progress label Aug 7, 2018
@@ -108,6 +111,8 @@ impl Transport for TcpConfig {
.map(|listener| {
// Pull out a stream of sockets for incoming connections
listener.incoming()
.sleep_on_error(Duration::from_secs(1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples all use 100ms, why did you opt for waiting a full second on the connection that errored?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be in the TcpConfig.

.map_err(|err| {
debug!("Error in TCP listener: {:?}", err);
err
})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While on it, why not also add the .listen(MAX_SIMULTANEOUS_CONNECTIONS) from the example - we could even make that configurable, putting the TcpConfig to good use finally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What listen does is handled by the swarm, although the swarm doesn't have a limit to the maximum number of connections at the moment and should have one.

@ghost ghost assigned gnunicorn Aug 8, 2018
@tomaka tomaka merged commit 5546bb9 into libp2p:master Aug 8, 2018
@tomaka tomaka deleted the ignore-tcp-errs branch August 8, 2018 15:54
@ghost ghost removed the in progress label Aug 8, 2018
mxinden added a commit to mxinden/rust-libp2p that referenced this pull request Aug 26, 2022
The `sleep_on_error` mechanism in `libp2p-tcp` would delay the next poll on the
listener stream when an error happens. This mechanism was introduced in
libp2p#402 based on the
[`tk_listen`](https://docs.rs/tk-listen/latest/tk_listen/) crate also referenced
in the tokio documentation.

When running out of file descriptors, the listening socket would return an
`EMFILE`. Instead of polling the socket again, thus likely receiving another
`EMFILE`, one would instead wait for 100ms.

Modern operating systems should run with high file descriptor limits and thus
this error should not happen in the wild. In addition, delaying the next poll
only covers up the issue, but does not solve it.

With the above in mind, this pull request removes the daly.

(The mention of `tk_listen` has since been removed from tokio.)
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