Skip to content

fix: thread-safety for static sets in Boavizta modules#148

Merged
jnioche merged 3 commits intoDigitalPebble:mainfrom
davide954:fix/boavizta-thread-safety
Feb 13, 2026
Merged

fix: thread-safety for static sets in Boavizta modules#148
jnioche merged 3 commits intoDigitalPebble:mainfrom
davide954:fix/boavizta-thread-safety

Conversation

@davide954
Copy link
Contributor

@davide954 davide954 commented Feb 13, 2026

PR to address the thread-safety discussion #146 regarding unknownInstanceTypes.

Todo

  • Replace HashSet with ConcurrentHashMap in BoaviztAPI.java
  • Replace HashSet with ConcurrentHashMap in BoaviztAPIstatic.java
  • Verify compilation

This ensures the module is safe for concurrent execution without significant performance overhead.

Description

Addresses the thread-safety concern regarding the static unknownInstanceTypes field, as discussed.

Since Spark tasks run concurrently within the same Executor JVM, sharing a non-thread-safe HashSet can lead to ConcurrentModificationException or infinite loops during map resizing.

@davide954 davide954 force-pushed the fix/boavizta-thread-safety branch from e4b0827 to 88f1a2c Compare February 13, 2026 15:19
Makes the access to shared data structures thread-safe.

Specifically, it replaces the `HashSet` with a `ConcurrentHashMap.newKeySet()` for storing unknown instance types, ensuring that multiple threads can safely update the set without causing race conditions or data corruption.
@davide954 davide954 marked this pull request as ready for review February 13, 2026 15:27
@jnioche
Copy link
Member

jnioche commented Feb 13, 2026

thanks @davide954
I would keep the instantiation lazy just like it is done for the other fields.

@jnioche jnioche added this to the 0.9 milestone Feb 13, 2026
@jnioche jnioche added the enhancement New feature or request label Feb 13, 2026
@jnioche jnioche changed the title [WIP] fix: thread-safety for static sets in Boavizta modules fix: thread-safety for static sets in Boavizta modules Feb 13, 2026
@jnioche jnioche merged commit 96f7585 into DigitalPebble:main Feb 13, 2026
2 checks passed
@jnioche
Copy link
Member

jnioche commented Feb 13, 2026

thanks @davide954

@davide954 davide954 deleted the fix/boavizta-thread-safety branch February 13, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants