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

Tokio-util codec Framed - cancel safety #5310

Closed
gopakumarce opened this issue Dec 24, 2022 · 1 comment · Fixed by #6417
Closed

Tokio-util codec Framed - cancel safety #5310

gopakumarce opened this issue Dec 24, 2022 · 1 comment · Fixed by #6417
Labels
A-tokio-util Area: The tokio-util crate M-codec Module: tokio-util/codec T-docs Topic: documentation

Comments

@gopakumarce
Copy link

gopakumarce commented Dec 24, 2022

Hi,

I cant see anywhere in the docs about the cancel safety of FramedRead and FramedWrite. Can anyone pls point me to any doc/code comments/anything that says whether those are cancel safe or not ?

Rgds,
Gopa.

@Darksonn Darksonn added T-docs Topic: documentation A-tokio-util Area: The tokio-util crate M-codec Module: tokio-util/codec labels Dec 24, 2022
@Darksonn
Copy link
Contributor

The documentation for tokio::select! has a section that lists some cancel safe methods. In particular, it mentions that StreamExt::next is cancel safe no matter what the stream is. Since FramedRead is a stream, the next method is cancel safe on them.

As for the sink methods on FramedWrite, well, if send is used as the event in a tokio::select! statement and some other branch completes first, then it is guaranteed that the message was not sent. That said, the message you're trying to send is lost if you cancel the send call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate M-codec Module: tokio-util/codec T-docs Topic: documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants