+
Skip to content

feat: advance next UID even if connection fails while fetching #6997

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

Merged
merged 1 commit into from
Jul 13, 2025

Conversation

link2xt
Copy link
Collaborator

@link2xt link2xt commented Jul 12, 2025

Connection sometimes fails while processing FETCH
responses. In this case fetch_new_messages exits early
and does not advance next expected UID even if
some messages were processed.

This results in prefetching the same messages
after reconnection and log messages
similar to
"Not moving the message ab05c85a-e191-4fd2-a951-9972bc7e167f@localhost that we have seen before.".

With this change we advance next expected UID
even if fetch_new_messages returns a network error.

Fixes #6936

@link2xt link2xt force-pushed the link2xt/advance-uid-next branch 5 times, most recently from 2c4e07b to 504387d Compare July 12, 2025 06:13
@link2xt link2xt marked this pull request as ready for review July 12, 2025 06:16
@r10s
Copy link
Contributor

r10s commented Jul 12, 2025

did bit read the code, just by the title:

if we advance UID if connection fails, we probably did not get that message. does that mean we're missing a message?

@iequidoo
Copy link
Collaborator

if we advance UID if connection fails, we probably did not get that message. does that mean we're missing a message?

Seems the only case when we can miss a message is when receive_imf_inner() returns a temporary error (see my comment above), but it's a corner case. In all other cases we advance the next UID only after receive_imf_inner() succeeds

@link2xt
Copy link
Collaborator Author

link2xt commented Jul 12, 2025

if we advance UID if connection fails, we probably did not get that message. does that mean we're missing a message?

There was a bug in this PR that actually resulted in lost messages, fixed in the second commit. But this is just a bug.

The idea of this PR is that if we have 10 messages that we decide to fetch after prefetch, and connection times out after fetching the first 4 messages, we want to advance UIDNEXT so we only prefetch the remaining 6 messages next time. Without this PR UIDNEXT did not advance in this case and we would prefetch 10 messages again on the next reconnection, even though we know that the first 4 messages are not interesting.

@iequidoo iequidoo self-requested a review July 12, 2025 20:30
@link2xt link2xt marked this pull request as draft July 13, 2025 03:22
@link2xt link2xt marked this pull request as ready for review July 13, 2025 03:23
@link2xt
Copy link
Collaborator Author

link2xt commented Jul 13, 2025

Thought about converting it to draft because I realized that FETCH result order is undefined, but fetch_many_msgs already handles reordering.

@link2xt link2xt force-pushed the link2xt/advance-uid-next branch 2 times, most recently from a118d4b to f2a59fa Compare July 13, 2025 15:42
Connection sometimes fails while processing FETCH
responses. In this case `fetch_new_messages` exits early
and does not advance next expected UID even if
some messages were processed.

This results in prefetching the same messages
after reconnection and log messages
similar to
"Not moving the message ab05c85a-e191-4fd2-a951-9972bc7e167f@localhost that we have seen before.".

With this change we advance next expected UID
even if `fetch_new_messages` returns a network error.
@link2xt link2xt force-pushed the link2xt/advance-uid-next branch from f2a59fa to d45ec7f Compare July 13, 2025 16:32
@link2xt link2xt merged commit d45ec7f into main Jul 13, 2025
17 checks passed
@link2xt link2xt deleted the link2xt/advance-uid-next branch July 13, 2025 16:32
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.

Advance last seen UID in the database immediately after each successful IMAP FETCH
3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载