Skip to content

Multiple connections are established, resulting in parser race condition #6

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

Open
aleclarson opened this issue Feb 20, 2025 · 0 comments

Comments

@aleclarson
Copy link

Hey there, Kane! First off, allow me to thank you for this package. It's been a great starting point for me. 🥇

Take a look at this code:

if (this.connectionInstance) return this.connectionInstance;
this.connectionInstance = await this.createConnection();

Since you are awaiting the createConnection call before assigning connectionInstance, a race condition is possible.

For example, if you fire off multiple commands before the connection is established, they will all be given their own connection, due to the logic error above. That means the responses can come out-of-order, and the parser may resolve the wrong promise, which can result in a crash if the caller was expecting an array response, but got null, for example.

I already solved this in my own fork:
https://github.com/alloc/redis-on-workers/blob/f5cd056c027c3642e45cb5583252e1b1cf2d527c/src/client.ts#L103-L183

Unfortunately, I've made so many changes that I won't be able to upstream the fix to your repo. 😅

Nonetheless, I hope this helps!


Btw, your isInitialized property is never set to true, resulting in unnecessary AUTH and SELECT commands.

private isInitialized = false;

OK, that's all for now. Peace!

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

No branches or pull requests

1 participant