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

net: allow to set linger on TcpSocket #4324

Merged
merged 1 commit into from
Dec 16, 2021
Merged

Conversation

fgaud
Copy link
Contributor

@fgaud fgaud commented Dec 16, 2021

For now, this is only allowed on TcpStream. This is a problem when one
want to disable lingering (i.e. set it to Duration(0, 0)). Without being
able to set it prior to the connect call, if the connect future is
dropped it would leave sockets in a TIME_WAIT state.

Motivation

We need to be able to disable lingering on the socket. Otherwise if we drop the connect call, close will cause the socket to move to TIME_WAIT which is a problem for us.

Solution

SO_LINGER is a socket option (https://man7.org/linux/man-pages/man7/socket.7.html), expose it as such similar to what is done for buffer sizes for example. I left the possibility to do that on the connected stream as well

Note that I reused the same comments than in TcpStream for consistency. I found that the last part [1] is a bit confusing but I thought that was better to keep that consistent.

[1] "If SO_LINGER is not specified, and the socket is closed, the system handles the call in a way that allows the process to continue as quickly as possible."

For now, this is only allowed on TcpStream. This is a problem when one
want to disable lingering (i.e. set it to Duration(0, 0)). Without being
able to set it prior to the connect call, if the connect future is
dropped it would leave sockets in a TIME_WAIT state.
@Darksonn Darksonn added A-tokio Area: The main tokio crate M-net Module: tokio/net labels Dec 16, 2021
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Seems good. Note that the method already exists on TcpStream, but adding it to TcpSocket as well is fine.

@Darksonn Darksonn merged commit 22e6aef into tokio-rs:master Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-net Module: tokio/net
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants