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

Fix RecyclerBytesStreamOutput allocating unlimited heap for some capacities #90632

Merged

Conversation

original-brownbear
Copy link
Member

We'd allocate infinite memory here because we'd overflow to negative capacities for newPosition close to Integer.MAX_VALUE.

…cities

We'd allocate infinite memory here because we'd overflow to negative
capacities for newPosition close to `Integer.MAX_VALUE`.
@original-brownbear original-brownbear added >bug :Distributed/Network Http and internode communication implementations v8.5.0 v7.17.7 v8.6.0 labels Oct 4, 2022
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Meta label for distributed team label Oct 4, 2022
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@elasticsearchmachine
Copy link
Collaborator

Hi @original-brownbear, I've created a changelog YAML for you.

// than Integer.MAX_VALUE
if (newPosition > Integer.MAX_VALUE - (Integer.MAX_VALUE % pageSize)) {
throw new IllegalArgumentException(getClass().getSimpleName() + " cannot hold more than 2GB of data");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we convert org.elasticsearch.common.io.stream.RecyclerBytesStreamOutput#currentCapacity to long to prevent this overflow? It looks like it is not used anywhere else. Such change would also allow us to make above limit configurable when needed.

Copy link
Contributor

@idegtiarenko idegtiarenko left a comment

Choose a reason for hiding this comment

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

Left a suggestion, otherwise LGTM 👍

@original-brownbear original-brownbear added the auto-backport-and-merge Automatically create backport pull requests and merge when ready label Oct 4, 2022
@original-brownbear
Copy link
Member Author

Thanks Ievgen, as discussed will address the suggestion in a follow-up.

@original-brownbear original-brownbear merged commit 7876282 into elastic:main Oct 4, 2022
@original-brownbear original-brownbear deleted the gigantic-recyler-unlucky branch October 4, 2022 09:17
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Oct 4, 2022
…cities (elastic#90632)

We'd allocate infinite memory here because we'd overflow to negative
capacities for newPosition close to `Integer.MAX_VALUE`.
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.5
7.17 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 90632

elasticsearchmachine pushed a commit that referenced this pull request Oct 4, 2022
…cities (#90632) (#90636)

We'd allocate infinite memory here because we'd overflow to negative
capacities for newPosition close to `Integer.MAX_VALUE`.
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Oct 4, 2022
@DaveCTurner
Copy link
Contributor

DaveCTurner commented Oct 4, 2022

Technically this wouldn't allocate unlimited heap because if currentCapacity wraps around enough then eventually it hits something ≥ newPosition. But we probably went OOM first... Edit: ah no I see it is genuinely unlimited for a 16kiB page size.

I think this deserves a test and it doesn't look too hard to do so without actually allocating GBs of heap - see #90638.

DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Nov 2, 2022
@DaveCTurner
Copy link
Contributor

@original-brownbear this is labelled 7.17 but I don't think RecyclerBytesStreamOutput exists in that branch. Did this bug affect something else there or is it mislabelled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-and-merge Automatically create backport pull requests and merge when ready >bug :Distributed/Network Http and internode communication implementations Team:Distributed Meta label for distributed team v7.17.7 v8.5.0 v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants