-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
tcp: deprecate TcpStream::try_clone()
#824
Conversation
@carllerche In #774 (comment), you said:
Do we really want to always return an error? I worry that this might break some otherwise working code. A deprecation warning should be enough, I think. |
You will have to merge master once #825 lands to fix the build. |
@stjepang it doesn't actually work as intended today, so any code that uses The issue is that each both stream handles will have separate In theory, it would be possible to make cloning work, but it would not be simple and add overhead to the non-cloned case. I'd rather better understand the use case for cloning here. |
Ok, I've turned Judging by https://github.com/guydunigo/tokio_test/blob/master/src/main.rs, I think @guydunigo wanted to have one task for writing into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Are there other try_clone fns to deprecate as well? |
There is also |
If it dups the fd, probably. |
@carllerche If we ever implement "real" async filesystem IO (e.g. with Linux AIO) and tie it to a reactor, then it will become a problem. cc @LucioFranco Since you've been reviewing code involving this function, do you perhaps have an opinion? |
@stjepang I am indifferent to keeping it but if its going to cause issues later down the line I am fine with removing it. So I see how this might cause issues though with the reactor and how it may cause more confusion down the line. So 👍 on deprecating |
// Rationale for deprecation: | ||
// - https://github.com/tokio-rs/tokio/pull/824 | ||
// - https://github.com/tokio-rs/tokio/issues/774#issuecomment-451059317 | ||
let msg = "`TcpStream::split()` is deprecated because it doesn't work as intended"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the message should be TcpStream::try_clone()
instead of TcpStream::split()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was eventually fixed:
Line 788 in 847fb59
let msg = "`TcpStream::try_clone()` is deprecated because it doesn't work as intended"; |
Motivation
TcpStream::clone()
creates a copy of a TCP stream that may be accidentally tied to a different reactor than the original. See here for a reproducible bug and here for a more elaborate explanation.Solution
Deprecate
TcpStream::try_clone()
and nudge users towardsTcpStream::split()
instead.Closes #774.