Skip to content

fix(api): Fix $text search timeout and rename DB_MAX_TIME_MESSAGES_SEARCH#1005

Closed
martian-str33t wants to merge 1 commit intozone-eu:masterfrom
sesamestr33t:text-search-timeout-upstream
Closed

fix(api): Fix $text search timeout and rename DB_MAX_TIME_MESSAGES_SEARCH#1005
martian-str33t wants to merge 1 commit intozone-eu:masterfrom
sesamestr33t:text-search-timeout-upstream

Conversation

@martian-str33t
Copy link
Copy Markdown
Contributor

Summary

  • Use longer timeout (DB_MAX_TIME_MESSAGES, 2min) for $text fulltext searches and shorter timeout (DB_MAX_TIME_FIELD_SEARCH, 3s) for indexed search.* field queries
  • Fix retry error variable (errerror) in the MaxTimeMSExpired catch block
  • Fix retry path setting maxTimeMS on wrong object (optsopts.fields)
  • Rename DB_MAX_TIME_MESSAGES_SEARCHDB_MAX_TIME_FIELD_SEARCH for clarity

Without this fix, $text searches on large mailboxes crash with MaxTimeMSExpired after 3 seconds because they were using the short field-search timeout instead of the generous fulltext timeout.

* #86c89t0yc: Fix $text search timeout on large mailboxes

- Use 2-minute timeout for $text searches instead of 3 seconds
  (DB_MAX_TIME_MESSAGES vs DB_MAX_TIME_MESSAGES_SEARCH)
- Fix retry to set opts.fields.maxTimeMS instead of opts.maxTimeMS
  (mongo-cursor-pagination reads from opts.fields)
- Fix retry catch block referencing outer err instead of error

* #86c89t0yc: Rename DB_MAX_TIME_MESSAGES_SEARCH to DB_MAX_TIME_FIELD_SEARCH
@NickOvt
Copy link
Copy Markdown
Contributor

NickOvt commented Mar 2, 2026

63811c7

In this commit I have added the shorter timeout, because there were issues with search on user accounts with lots of mailboxes (over 200), in which case it made sense to not pin the search on a mailbox, if the search took too much time. The logic was as follows: If the search took more time than 3 seconds, then we get the timeout error, and retry search without pinning the mailbox and with a longer timeout (2 mins).
All other changes in this PR are good.
Remove the changes in consts.js and remove this change maxTimeMS: isTextSearch ? consts.DB_MAX_TIME_MESSAGES : consts.DB_MAX_TIME_FIELD_SEARCH and I will accept and merge the PR.

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