/claim #9681

Proposed changes

This PR hardens the Scala Native concurrent-set path used by WeakConcurrentBag during fork-heavy workloads:

  • Native PlatformSpecific.newConcurrentSet now uses:
    • Collections.newSetFromMap(new ConcurrentHashMap(...))
  • It avoids the ConcurrentHashMap.newKeySet(...).add (KeySetView) code path seen in #9681 stack traces.

I also added regression-oriented native stress coverage:

  • core-tests/shared/src/test/scala/zio/internal/ConcurrentSetSpec.scala
    • concurrent insert stress with colliding hash codes (nonFlaky(25), nativeOnly)
  • PromiseSpec
    • waiter stack safety under sustained forking pressure

Why this shape

A first attempt using synchronized HashSet avoided the NPE path but failed concurrent correctness under stress (lost inserts). This version keeps true concurrent-map backing while avoiding newKeySet.

Proof

Commands executed locally:

SBT_OPTS='-Xms1G -Xmx3G -Xss4M -XX:+UseG1GC' sbt \
"coreTestsNative/testOnly zio.internal.ConcurrentSetSpec -- -t \"handles colliding hash codes under concurrent inserts\"" \
"coreTestsNative/testOnly zio.PromiseSpec -- -t \"waiter stack safety\""

Results:

  • ConcurrentSetSpec passed (25 repeated runs)
  • PromiseSpec waiter stack-safety tests passed

Claim

Total prize pool $150
Total paid $0
Status Pending
Submitted March 04, 2026
Last updated March 04, 2026

Contributors

LI

Liuyi Yu

@yuliuyi717-ux

100%

Sponsors

ZI

ZIO

@ZIO

$150