/claim #9681 Fix- #9681
The PromiseSpec
test “waiter stack safety” fails with a NullPointerException
on Scala Native when forking 10,000 fibers. The issue occurs in WeakConcurrentBag
due to a bug in Scala Native’s ConcurrentHashMap.newKeySet
implementation under high concurrency.
Scala Native’s ConcurrentHashMap.newKeySet()
has concurrency issues that cause NPEs when multiple threads access it simultaneously during high-stress scenarios like forking 10K fibers.
Replace ConcurrentHashMap.newKeySet
with Collections.synchronizedSet(new HashSet[A]())
in the Scala Native-specific PlatformSpecific.scala
. This provides thread-safe set operations without the concurrency bugs present in Scala Native’s ConcurrentHashMap implementation.
core/native/src/main/scala/zio/internal/PlatformSpecific.scala
:
ConcurrentHashMap.newKeySet[A]()
with Collections.synchronizedSet(new HashSet[A]())
ConcurrentHashMap.newKeySet[A](initialCapacity)
with Collections.synchronizedSet(new HashSet[A](initialCapacity))
HashSet
importhttps://drive.google.com/file/d/1SqJPecRrI51hFZcm9Qz_3LQpY9wmimUd/view?usp=sharing
The previously failing test now passes consistently:
sbt "project coreTestsNative" "testOnly *PromiseSpec* -- -z \"waiter stack safety\""
Sonal Yadav
@sonalyadav1
ZIO
@ZIO