Skip to content

Conversation

Copy link

Copilot AI commented Jan 20, 2026

Multiple classes using CompletableFutures and virtual threads had race conditions from unsynchronized access to shared mutable state.

Changes

  • DiscordRPCManager: Atomic types for updateTask/startTimeStamp/cycleCount to fix check-then-act races and non-atomic updates
  • SecretsTracker: ConcurrentHashMap in TrackedRun record to prevent corruption from concurrent modifications across START/END phases
  • ProfileViewerScreen: Volatile fields (hypixelProfile, playerProfile, entity, etc.) for visibility of async writes to render thread
  • BackpackPreview: AtomicReferenceArray for storages to guarantee visibility and atomic operations across threads
  • SkyblockerWebSocket: Null-check in sendInternal with local snapshot to prevent NPE from volatile socket becoming null mid-execution
  • ItemRepository: Volatile itemsImported/filesImported flags for visibility across async loading and synchronous reads

Example fix pattern:

// Before: race condition
if (updateTask == null || updateTask.isDone()) {
    updateTask = CompletableFuture.runAsync(...);
}

// After: atomic reference
CompletableFuture<Void> currentTask = updateTask.get();
if (currentTask == null || currentTask.isDone()) {
    CompletableFuture<Void> newTask = CompletableFuture.runAsync(...);
    updateTask.set(newTask);
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • maven.fabricmc.net
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -Xmx1G -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant (dns block)
  • www.puppycrawl.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.23.8/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.23.8/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.23.8/x64/codeql/xml/tools/xml-extractor.jar --fileList=/home/REDACTED/work/Skyblocker/.codeql-scratch/dbs/java/working/files-to-index2436791691584961716.list --sourceArchiveDir=/home/REDACTED/work/Skyblocker/.codeql-scratch/dbs/java/src --outputDir=/home/REDACTED/work/Skyblocker/.codeql-scratch/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Review and identify non-thread-safe code that could lead to race conditions or have unwanted effects. Review the use of concurrency, completable futures, and virtual threads.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@LifeIsAParadox LifeIsAParadox added the wip This PR is a work in progress label Jan 20, 2026
@kevinthegreat1
Copy link
Collaborator

Ok I didn't know it was going to make a pr...

@kevinthegreat1
Copy link
Collaborator

Don't make just random code thread-safe. Only check for thread safety in actual concurrent code that is being accessed by multiple threads.

Copilot AI changed the title [WIP] Review concurrency and identify non-thread-safe code Fix thread-safety issues in concurrent code paths Jan 20, 2026
Copilot AI requested a review from kevinthegreat1 January 20, 2026 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wip This PR is a work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants