-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[question] Question on concurrent writer. #596
Comments
Hello ~ can you provide sample code? |
No, the documentation says it's not allowed. Use a mutex or some other form of synchronization.
You were lucky. |
Yes, I got panic eventually... |
This can be closed imho. |
I get why you can't support more than one concurrent writer and don't have any real problem using a mutex, but since you specifically don't allow more than one writer, why not just have the mutex inside of the websocket struct? why force every person that uses the code to implement the mutex in their application? |
@justinrush A mutex is not needed when a single goroutine writes to the connection. None of the examples in this repository use a mutex. There's not a single method where the mutex should be locked/unlocked. In the following code, the lock comes before setting deadline and after closing the writer. I think it would have been better to design the API so the connection can manage the lock, but it's too late for that.
|
Ya, it just feels like its pretty common to have an app design where you end up needing the mutex. It makes sense that the ship has sailed on including it by default in the library as there are a bunch of projects that are already doing the locking. Thanks for following up |
@justinrush It may be common to use a mutex, but it's a lot easier to avoid server stalls on dead or stuck clients using a goroutine. Most users of mutexes should probably be using a goroutine to ensure no more than one concurrent writer. |
Without attempting to read garyburd's mind I would assume the reasoning here is simple; the package is meant to implement the websocket RFC, without attempting to assume how it will be used. Put even more simply; application logic belongs in the application. |
@IngCr3at1on and the ghost answered all of the questions in this issue. |
Describe the problem you're having
So my problem is could we use 2 or more goroutine for Write method? I used 2 goroutine without any mutex, but it looked all good.
…
Versions
…
"Show me the code!"
…
The text was updated successfully, but these errors were encountered: