Skip to content

Fix panic on query with huge limit - #5484

Merged
generall merged 4 commits into
devfrom
fix-panic-on-huge-query-limit
Nov 19, 2024
Merged

generall merged 4 commits into
devfrom
fix-panic-on-huge-query-limit

Conversation

@timvisee

@timvisee timvisee commented Nov 19, 2024 •

Copy link
Copy Markdown
Member

Fixes #5483

Here we started to preallocate memory in the search result aggregator based on the user provided limit. If a user provides a huge limit it will panic due to an allocation failure.

This PR fixes the problem by limiting the size of preallocating to one million items, exactly like FixedLengthPriorityQueue does. I'm not entirely sure if one million is reasonable here, and it might be too big. Lets discuss here what we think may be reasonable.

I've also fixed a limit overflow in FixedLengthPriorityQueue if a limit of u64::MAX is given, and an overflow in search.

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Prevents an allocation failure and panic if a user specifies a huge
search limit.
@timvisee
timvisee marked this pull request as ready for review November 19, 2024 16:38
@timvisee
timvisee force-pushed the fix-panic-on-huge-query-limit branch from 48237dd to f2a90a9 Compare November 19, 2024 16:44
use segment::types::{PointIdType, ScoredPoint, SeqNumberType};

/// Avoid excessive memory allocation and allocation failures on huge limits
const LARGEST_REASONABLE_ALLOCATION_SIZE: usize = 1_048_576;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a lower value should be enough if we want to protect ourselves.

Something like 8,192

@agourlay agourlay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests 🙏

@generall
generall merged commit a4cd725 into dev Nov 19, 2024
@generall
generall deleted the fix-panic-on-huge-query-limit branch November 19, 2024 19:53
timvisee added a commit that referenced this pull request Dec 9, 2024
* Limit maximum preallocation on search results aggregator hash set

Prevents an allocation failure and panic if a user specifies a huge
search limit.

* Prevent overflow on fixed length priority queue limit with u64::MAX

* Fix overflow with high limit in search API

* Add two basic tests covering high search limit
@timvisee timvisee mentioned this pull request Dec 9, 2024
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.

3 participants