Skip to content

fix(transformers): serialize UTCTimestampTransformer to avoid rng race#802

Open
SAY-5 wants to merge 3 commits into
xataio:mainfrom
SAY-5:fix/timestamp-rng-race-789
Open

fix(transformers): serialize UTCTimestampTransformer to avoid rng race#802
SAY-5 wants to merge 3 commits into
xataio:mainfrom
SAY-5:fix/timestamp-rng-race-789

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 3, 2026

Closes #789.

greenmask's Timestamp transformer holds a *rand.Rand instance that's not safe for concurrent use, but pgstream shares one UTCTimestampTransformer across all snapshot worker goroutines. Concurrent calls corrupt the shared rng and panic deep inside math/rand.(*rngSource).Uint64 with index out of range [-1].

Guard the Transform call with a per-instance mutex. The same pattern likely applies to the other greenmask transformer wrappers in this package, happy to extend in a follow-up if you'd like, but kept this PR narrow to the surface in the bug report.

greenmask's Timestamp holds a *rand.Rand that is not concurrency-safe,
but pgstream shares one transformer across snapshot worker goroutines.
Concurrent calls corrupted the shared rng and panicked deep in
math/rand.(*rngSource).Uint64. Guard the Transform call with a
per-instance mutex.

Signed-off-by: SAY-5 <[email protected]>
@kvch
Copy link
Copy Markdown
Collaborator

kvch commented May 7, 2026

Thank you for the contribution. We try to fix these issues in our fork or greenmask. Do you mind submitting a fix to this repo? https://github.com/xataio/greenmask

@SAY-5
Copy link
Copy Markdown
Author

SAY-5 commented May 7, 2026

Thanks for the pointer. The transformer surface in greenmask looks different from pgstream's, so the fix doesn't port 1:1, would you prefer I close this PR and let you sync the equivalent change into greenmask on the maintainers' next pass, or leave this open as a reference?

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.

Panic / runtime error generating random numbers for greenmask timestamp transformer

2 participants