[ 
https://issues.apache.org/jira/browse/GROOVY-12457?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18128375#comment-18128375
 ] 

ASF GitHub Bot commented on GROOVY-12457:
-----------------------------------------

codecov-commenter commented on PR #2986:
URL: https://github.com/apache/groovy/pull/2986#issuecomment-6248259525

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/2986?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 Report
   :x: Patch coverage is `85.85859%` with `14 lines` in your changes missing 
coverage. Please review.
   :white_check_mark: Project coverage is 72.4184%. Comparing base 
([`d77e6df`](https://app.codecov.io/gh/apache/groovy/commit/d77e6df56a8d59ca30afbfa4c66afb9c685a22db?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`c5a58cb`](https://app.codecov.io/gh/apache/groovy/commit/c5a58cbd220c9af08d8e20df50efd81dc5f2af1c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/2986?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Patch % | Lines |
   |---|---|---|
   | 
[...s/groovy/runtime/ParallelCollectionExtensions.java](https://app.codecov.io/gh/apache/groovy/pull/2986?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fruntime%2FParallelCollectionExtensions.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3J1bnRpbWUvUGFyYWxsZWxDb2xsZWN0aW9uRXh0ZW5zaW9ucy5qYXZh)
 | 85.8586% | [12 Missing and 2 partials :warning: 
](https://app.codecov.io/gh/apache/groovy/pull/2986?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree 
graph](https://app.codecov.io/gh/apache/groovy/pull/2986/graphs/tree.svg?width=650&height=150&src=pr&token=1r45138NfQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/groovy/pull/2986?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #2986        +/-   ##
   ==================================================
   + Coverage     72.4166%   72.4184%   +0.0018%     
   - Complexity      40606      40634        +28     
   ==================================================
     Files            1643       1643                
     Lines          142633     142711        +78     
     Branches        26788      26792         +4     
   ==================================================
   + Hits           103290     103349        +59     
   - Misses          29850      29862        +12     
   - Partials         9493       9500         +7     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/2986?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[...s/groovy/runtime/ParallelCollectionExtensions.java](https://app.codecov.io/gh/apache/groovy/pull/2986?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fruntime%2FParallelCollectionExtensions.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3J1bnRpbWUvUGFyYWxsZWxDb2xsZWN0aW9uRXh0ZW5zaW9ucy5qYXZh)
 | `86.2319% <85.8586%> (-3.7681%)` | :arrow_down: |
   
   ... and [12 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/2986/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test 
Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, 
report on failures, and find test suite problems.
   - :package: [JS Bundle 
Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save 
yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>




> Blocking parallel-collection callbacks can fail to run a queued sibling task
> ----------------------------------------------------------------------------
>
>                 Key: GROOVY-12457
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12457
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Daniel Sun
>            Priority: Major
>
> h2. Context
> {{{}eachParallel{}}}, {{{}collectParallel{}}}, and the other parallel 
> collection methods run their callback on a {{{}ForkJoinPool{}}}: the pool 
> bound by {{{}ParallelScope.withPool{}}}, or {{ForkJoinPool.commonPool()}} 
> when no pool is bound. {{@Parallel}} {{for-in}} loops are rewritten to call 
> {{{}eachParallel{}}}. The methods arrived with GROOVY-11952 
> ([GEP-18|https://groovy.apache.org/wiki/GEP-18.html]).
> A pool of size {{n}} is the intended way to run {{n}} callbacks that block at 
> the same time.
> h2. Problem
> This rendezvous fails intermittently, including when the pool size equals the 
> number of parties:
> {code:groovy}
> import groovy.concurrent.ParallelScope
> import java.util.concurrent.CyclicBarrier
> import java.util.concurrent.TimeUnit
> int parties = 2
> ParallelScope.withPool(parties) { scope ->
>     def barrier = new CyclicBarrier(parties)
>     (1..parties).eachParallel {
>         barrier.await(5, TimeUnit.SECONDS)
>     }
> }
> {code}
> {{CyclicBarrier.await}} throws {{TimeoutException}} because the second 
> element never starts. The failure is reported as a nested 
> {{{}UndeclaredThrowableException{}}}:
> ||Layer||What the caller sees||
> |Closure|{{TimeoutException}} from {{CyclicBarrier.await}}|
> |{{Consumer}} proxy|{{{}UndeclaredThrowableException{}}}, because {{accept}} 
> does not declare checked exceptions|
> |{{ForkJoinTask.getThrowableException}}|A second 
> {{{}UndeclaredThrowableException{}}}, rebuilt on the joining thread|
> The same shape fails for {{@Parallel}} {{{}for (item in 1..n){}}}. It shows 
> up more often once the pool's workers have already run and parked. A freshly 
> created pool can fail as well.
> h2. Cause
> {{parallelStream()}} forks the sibling leaf onto the current worker's queue, 
> then runs one leaf on that same worker. {{CyclicBarrier.await}} is not a 
> {{{}ForkJoinPool.ManagedBlocker{}}}, so the pool does not release or replace 
> the blocked worker. If the other worker has already scanned and parked, the 
> fork signal is not always delivered again. The sibling stays on the queue 
> until the barrier times out.
> Sizing the pool to exactly {{n}} threads does not close the race. The idle 
> thread is there; it is parked.
> h2. Change
> The proposed change runs the user callback inside 
> {{ForkJoinPool.managedBlock}} when the current worker still has queued tasks. 
> That releases a parked worker, or creates a spare, before the callback can 
> block. A leaf whose queue is empty is unchanged.
>  * JDK 20 and later read {{{}ForkJoinWorkerThread.getQueuedTaskCount(){}}}.
>  * JDK 17 does not have that method, so the check uses the pool-wide 
> queued-task estimate.
> The wrapper covers every parallel-collection callback, including 
> {{eachWithIndexParallel}} and the {{eachParallel}} call emitted for 
> {{{}@Parallel{}}}.
> Compensation runs only when a sibling is already queued. A callback that 
> blocks before any sibling has been forked can still stall, and so can a pool 
> that refuses another thread. Work that spends most of its time waiting still 
> fits {{Pool.io()}} or {{Pool.virtual()}} better than a fixed 
> {{{}ForkJoinPool{}}}.
> h2. Tests
>  * {{ParallelCollectionTest}} and {{ParallelAnnotationTest}} repeat the 
> two-party barrier on one pool, so later rounds run against workers parked by 
> the first round. The barrier must trip.
>  * The thread-count assertion allows a spare ({{{}size() >= parties{}}}), 
> because {{managedBlock}} may add one while a worker is blocked.
>  * The full two test classes passed on JDK 25. The three barrier tests also 
> passed on JDK 17, which exercises the queue-length fallback.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to