Skip to content
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 WriteServerMessage thread-safe? #176

Open
nncsang opened this issue May 24, 2023 · 9 comments
Open

Is WriteServerMessage thread-safe? #176

nncsang opened this issue May 24, 2023 · 9 comments
Labels

Comments

@nncsang
Copy link

nncsang commented May 24, 2023

I have experienced the "Invalid frame header" and "One or more reserved bits are on: reserved1 = 0, reserved2 = 1, reserved3 = 0" when calling WriteServerMessage concurrently from multiple goroutines.

@cristaloleg
Copy link
Collaborator

No, it's not thread safe.

@nncsang
Copy link
Author

nncsang commented May 24, 2023

@cristaloleg is there any function supporting writing message to a connection concurrently?

@cristaloleg
Copy link
Collaborator

Just access it with sync.Mutex and voila. You can share a small code snippet, so it will be easier to suggest what/where to change.

@mahditakrim
Copy link

@cristaloleg How about ws package?

@cristaloleg
Copy link
Collaborator

What exactly?

@mahditakrim
Copy link

@cristaloleg is ws write methods thread safe?

@cristaloleg
Copy link
Collaborator

Sorry, missed your response. Depends on the param, functions themself are thread-safe, params might not be.

@leedstyh
Copy link

hi @cristaloleg , is it thread-safe between wsutil.WriteServerMessage() and wsutil.ReadClientText() ?

I guess wsutil.ReadClientText() writes pong message sometimes.

@cristaloleg
Copy link
Collaborator

These are just funcs, they depend only on the given params. If a passed io.ReadWriter is not thread-safe you might get a data race.

I guess wsutil.ReadClientText() writes pong message sometimes.

I don't see any write-specific call in it. Can you clarify why you think it writes pong messages?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants