Skip to content

Fix RecyclerBytesStreamOutput allocating unlimited heap for some capacities#90632

Merged
original-brownbear merged 2 commits intoelastic:mainfrom
original-brownbear:gigantic-recyler-unlucky
Oct 4, 2022
Merged

Fix RecyclerBytesStreamOutput allocating unlimited heap for some capacities#90632
original-brownbear merged 2 commits intoelastic:mainfrom
original-brownbear:gigantic-recyler-unlucky

Conversation

@original-brownbear
Copy link
Copy Markdown
Contributor

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
Copy Markdown
Collaborator

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

@elasticsearchmachine
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy link
Copy Markdown
Contributor Author

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

@elasticsearchmachine
Copy link
Copy Markdown
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
Copy Markdown
Member

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
Copy Markdown
Member

@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

>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.

4 participants