Skip to content

feat: close ImapStream after an error #122

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

link2xt
Copy link
Contributor

@link2xt link2xt commented Jul 22, 2025

This prevents calls to poll_next()
from reaching the underlying stream
after an error is returned once.

Previously calls to poll_next()
to ImapStream built on top
of a network connection
could have returned infinite
stream of Some(Err(_))
values.
This is dangerous
for the code that looks for the end
of stream without processing
errors such as
while stream.next().await.is_some() {}
because it may result in
infinite loop.

It is still better to process
errors by writing
while stream.try_next().await?.is_some() {},
but the change protects
in case of incorrect library user code.

@link2xt link2xt force-pushed the link2xt/wkqlzyzmrouk branch 2 times, most recently from eb05ceb to 8a36a80 Compare August 2, 2025 23:26
This prevents calls to poll_next()
from reaching the underlying stream
after an error is returned once.

Previously calls to poll_next()
to ImapStream built on top
of a network connection
could have returned infinite
stream of Some(Err(_))
values.
This is dangerous
for the code that looks for the end
of stream without processing
errors such as
`while stream.next().await.is_some() {}`
because it may result in
infinite loop.

It is still better to process
errors by writing
`while stream.try_next().await?.is_some() {}`,
but the change protects
in case of incorrect library user code.
@link2xt link2xt force-pushed the link2xt/wkqlzyzmrouk branch from 8a36a80 to df021a7 Compare August 2, 2025 23:28
@link2xt
Copy link
Contributor Author

link2xt commented Aug 2, 2025

I have added a test now.

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