Detect TCP disconnect without reading or writing anything to that socket? #2228
Labels
A-tokio
Area: The main tokio crate
C-feature-accepted
Category: A feature request that has been accepted pending implementation.
C-feature-request
Category: A feature request.
M-net
Module: tokio/net
Version
Description
In #483, it was discussed to use
poll_read_ready(Ready::empty())
for detecting TCP disconnect.After that,
poll_read_ready()
was removed at 6d8cc4e according to a discussion on gitter as described in #1392 (comment).Is there any alternative way to detect TCP disconnect without writing or reading anything to/from that socket?
I haven't tried yet, but we might be able to use
peek()
orpoll_peek()
for this purpose.Background
In some situations, it's necessary to detect TCP disconnect without reading or writing anything to/from that socket.
For example, suppose an HTTP server that performs a time-consuming task for a response. This HTTP server don't like to read data from the TCP socket for detecting disconnect in order to support HTTP keep-alive and request pipelining easily. This HTTP server has no data to write until the task outputs something.
If there is no way to detect TCP disconnect other than reading/writing, this HTTP server cannot detect TCP disconnect until the task outputs something.
The similar situation occurs in
actix-web
. And it seems to leak TCP sockets if clients disconnect while it waits for data from aStream
object:https://github.com/masnagam/rust-case-studies/tree/master/actix-web-streaming-and-tcp-disconnect
Related Issues
Example of detecting TCP disconnect using
poll_read_ready()
The text was updated successfully, but these errors were encountered: