/claim #9681
This PR hardens the Scala Native concurrent-set path used by WeakConcurrentBag during fork-heavy workloads:
PlatformSpecific.newConcurrentSet now uses:
Collections.newSetFromMap(new ConcurrentHashMap(...))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
nonFlaky(25), nativeOnly)PromiseSpec
waiter stack safety under sustained forking pressureA 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.
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 passedLiuyi Yu
@yuliuyi717-ux
ZIO
@ZIO