Skip to content

fix: Signal.ref race condition from unsynchronized mutable var (#4023)#4028

Merged
987Nabil merged 1 commit intozio:mainfrom
987Nabil:fix/datastar-signal-ref
Mar 14, 2026
Merged

fix: Signal.ref race condition from unsynchronized mutable var (#4023)#4028
987Nabil merged 1 commit intozio:mainfrom
987Nabil:fix/datastar-signal-ref

Conversation

@987Nabil
Copy link
Copy Markdown
Contributor

@987Nabil 987Nabil commented Mar 13, 2026

Summary

Fix race condition in Signal.ref caused by an unsynchronized mutable var.

Bug

Signal.ref used a private var ref0: String = null with a check-and-set pattern that was not thread-safe. Concurrent access could result in null returns or duplicate computation.

Fix

Replace private var ref0 + def ref with lazy val ref, which is thread-safe in Scala (uses a synchronized initialization block under the hood, zero-cost after first access).

The primitive-type restriction and RuntimeException for non-primitive types are preserved — that semantic constraint is correct and will be improved to a compile-time check in zio-http 4.

Fixes #4023

Copilot AI review requested due to automatic review settings March 13, 2026 15:23
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 13, 2026

Deploy Preview for zio-http ready!

Name Link
🔨 Latest commit eceabe4
🔍 Latest deploy log https://app.netlify.com/projects/zio-http/deploys/69b540753758b70008990b34
😎 Deploy Preview https://deploy-preview-4028--zio-http.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@987Nabil 987Nabil force-pushed the fix/datastar-signal-ref branch from d8d3990 to eceabe4 Compare March 14, 2026 11:03
@987Nabil 987Nabil changed the title fix: remove primitive restriction and race condition from Signal.ref fix: Signal.ref race condition from unsynchronized mutable var (#4023) Mar 14, 2026
@987Nabil 987Nabil merged commit 006e8b2 into zio:main Mar 14, 2026
83 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(datastar): Signal.ref incorrectly restricts to primitive types and has race condition

2 participants