Skip to content

fix(extension-redis): redlock release race condition#958

Merged
janthurau merged 6 commits intoueberdosis:mainfrom
mattkrick:fix/redlock-release-race
Jul 24, 2025
Merged

fix(extension-redis): redlock release race condition#958
janthurau merged 6 commits intoueberdosis:mainfrom
mattkrick:fix/redlock-release-race

Conversation

@mattkrick
Copy link
Contributor

Fixes a race condition with the redis extension where if 2 actors try to edit the same document in quick succession it starts to fail.

I also updated to the latest version of redlock. Since redlock is no longer maintained, everyone started using this fork that is written in typescript and uses ioredis v5.

The bug was so wild I wrote a blog post on it, hopefully it describes the problem better: https://www.mattkrick.dev/blog/troubleshooting-redlock-guarantees-and-pitfalls.

Signed-off-by: Matt Krick <matt.krick@gmail.com>
@janthurau
Copy link
Contributor

@mattkrick Thanks a lot for your PR!

Unfortunately the tests are failing here with what seems to be a known problem: sesamecare/redlock#6. Wondering how this is working on your end 🤔 ?

@mattkrick
Copy link
Contributor Author

mattkrick commented Jul 2, 2025

interesting! In prod I use uWS, so perhaps it's specific to the websocket implementation. I'll dig deeper

note to self: can reproduce if the extension before redis (Database) throws inside onStoreDocument. Need to dig into how exceptions are handled in chained extensions and bail gracefully

Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
@mattkrick
Copy link
Contributor Author

testing locally, I was able to reproduce the error by making a change on the client & then inside onStoreDocument I opened a direct connection & made another change.
this caused onStoreDocument to get called twice in quick succession. Since the previous redlock config had retryCount: 0 it failed. by removing that constraint the tests seem to pass now

@janthurau janthurau merged commit 5666a65 into ueberdosis:main Jul 24, 2025
6 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.

3 participants

Comments