-
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
[feature] concurrent safe write function #826
Comments
Concurrent writes are the top support issue for this package. It's not useful to make the current methods threadsafe given the overall design of the API, but it might be worth doing to reduce the support burden. |
I've been thinking about this for awhile. Do we support thread-safeness into the future or do we just say "too bad" and ask folks to find a better library. I'm not entirely sure. |
Drive the concurrency-related issues elsewhere by making the individual methods threadsafe. Support thread safety into the future. Developers of robust applications will want to handle concurrency within their application code. The current API is no hindrance to those developers and may be preferable to other APIs. I read through the examples in this repository and don't see how additional thread safety in the package will benefit them. Perhaps I need to spend more time looking at them. As an interesting side note, none of the examples use sync.Mutex. |
Given that deadline, compression and compression level are set by separate methods, it does not make sense to support concurrent calls to NextWriter, WriteMessage and WriteJSON. A previous comment suggests that the support burden can be reduced by making the individual methods thread-safe. That's a lot of work for something that does not make sense. That said, there is some low-hanging fruit. Based on a scan through the issues tracker, it looks like most of the concurrent writes are through WriteMessage and WriteJSON. Adding a mutex to protect those two calls will probably eliminate most of the reported |
No, tell them to fix their code by writing from a single goroutine or by using a mutex. You can also create a new higher-level package that encapsulates a common use pattern for the package, namely the read and write pump from the chat example (but not the chat example's hub). This package can address concurrent write and other common needs such as liveness detection. The package would not add protocol above the websocket layer or be applicable to all use cases. |
currently, the implementation of the write series function is concurrency-unsafe, it is recommended to introduce a concurrency-safe write function
The text was updated successfully, but these errors were encountered: