-
Notifications
You must be signed in to change notification settings - Fork 18k
testing/synctest: isolation failure in encoding/json #73733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
FYI, the v2 implementation doesn't wait for completion for computation for the full type tree: go/src/encoding/json/v2/arshal.go Line 543 in 6df855e
It defers recursive type computation lazily with a go/src/encoding/json/v2/arshal_default.go Lines 707 to 715 in 6df855e
|
Change https://go.dev/cl/673335 mentions this issue: |
Isn’t this an issue that anybody using synctest could easily run into while writing completely valid code? Why wouldn’t we want to address the underlying issue, rather than the symptom? |
Do you have a specific suggestion on how we can address the underlying issue? There's quite a bit of discussion in #67434 about the general problem of goroutines in a synctest bubble accessing global concurrency constructs. We arrived at a set of compromises which I think are, while imperfect, good enough to make the synctest package more useful than not. I don't believe there is any perfect solution to this problem, although it's probable that we can do better than the current implementation. (In particular, it's worth considering whether we can report cross-bubble use of a WaitGroup as happened here--if this had been a panic, it would still be a problem but it would have been a simpler one to diagnose.) |
encoding/json uses a WaitGroup to coordinate access to a cache between multiple goroutines:
https://go.googlesource.com/go/+/refs/tags/go1.24.3/src/encoding/json/encode.go#359
When multiple synctest bubbles access the cache at the same time, a goroutine in one bubble can become blocked on a goroutine in the other bubble. Since we don't track whether the WaitGroup was created in a bubble, or which bubble it was created in, this looks like a deadlock to synctest.
A possible fix is to change encoding/json to use a sync.Once here. A goroutine blocked on a Once is not "durably" blocked in synctest terms. Also, a sync.Once is probably a clearer way of expressing the intent of this encoding/json code.
The text was updated successfully, but these errors were encountered: