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
Is Conn thread-safe? #6
Comments
Everything in this package is synchronized internally and safe to use |
Thanks very much @kr ! One question still remains though: sharing a single connection to Beanstalkd is rather hard to deal with due to the blocking nature of |
Sharing a single connection should do the right thing with server On the other hand, you can open as many connections as you like. It's up to you. |
I see. I think I'll go with one connection per goroutine for better isolation of concerns. Thanks very much for the explanation! |
I'm not sure that's right. Sure the connection serializes commands but I think there can be a situation where 2 commands are sent then 2 responses are read. So I think the lib is co-routine safe but not protocol safe. Can you confirm? |
Sending commands are serialized, and reading responses are serialized in the same order. So yes, it's possible for two goroutines A and B to send commands A and B, then read responses A and B. The server will send its responses in order and the client will read them in order. So it is safe to call, for example, Stats and Touch concurrently from two goroutines. Or Reserve and Delete and Peek. Or any other combination of two or more commands.
Sorry, I'm afraid I don't understand what you mean by this distinction. |
What about... coroutine 1 sends command I just try to wrap my head around text protocol :) |
Oh I just understood, you are absolutely right it is coroutine safe, I just read this example from text protocol: https://golang.org/pkg/net/textproto/#Pipeline You are using the same ID to write a request and read a response. Thanks |
From the code I assume it's not. If so, what's the recommended strategy for multiple goroutines to work with a Beanstalk server? Use multiple connections, or share one connection with a lock?
The text was updated successfully, but these errors were encountered: