Skip to content

Conversation

@idegtiarenko
Copy link
Contributor

@idegtiarenko idegtiarenko commented May 22, 2025

Today Iterables.size is implemented as following:

    public static long size(Iterable<?> iterable) {
        return StreamSupport.stream(iterable.spliterator(), true).count();
    }

please note the second parameter passed to stream call: parallel=true.
A parallel stream starts a fork join ForkJoinPool. It is never closed here as stream is not closed explicitly nor used in try block.

This results in a thread leak that was detected in #127196. Surprisingly it was only happening on JDK 21.

I do not think there is any benefit of counting number of entries concurrently so I am changing the call to use non-parallel stream.

This method is also used in prod, so I am adding core/infra to this review.

Closes: #127196

@idegtiarenko idegtiarenko requested review from dnhatn and nik9000 May 22, 2025 15:33
@idegtiarenko idegtiarenko requested a review from a team as a code owner May 22, 2025 15:33
@idegtiarenko idegtiarenko added >test Issues or PRs that are addressing/adding tests :Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL v8.19.0 v9.1.0 labels May 22, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Copy link
Contributor

@ldematte ldematte left a comment

Choose a reason for hiding this comment

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

LGTM; since this is a generic thing, it's "surprising" to have this parallel. Better be sequential by default (if someone is in the special situation of needing to do a parallel count due to size, they should be the special case)

@idegtiarenko idegtiarenko merged commit 2f01d17 into elastic:main May 23, 2025
18 checks passed
@idegtiarenko idegtiarenko deleted the fix_127196 branch May 23, 2025 06:36
idegtiarenko added a commit to idegtiarenko/elasticsearch that referenced this pull request May 23, 2025
elasticsearchmachine pushed a commit that referenced this pull request May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL :Core/Infra/Core Core issues without another label Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:Core/Infra Meta label for core/infra team >test Issues or PRs that are addressing/adding tests v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI] ManyShardsIT class failing

5 participants