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

Any example for using this library with gnet? #201

Closed
spy16 opened this issue May 11, 2024 · 5 comments
Closed

Any example for using this library with gnet? #201

spy16 opened this issue May 11, 2024 · 5 comments
Labels

Comments

@spy16
Copy link

spy16 commented May 11, 2024

I am trying to use gobwas/ws with https://github.com/panjf2000/gnet library in an attempt to build a high-performance websocket server.

I am running into io.ErrShortBuffer error under two cases:

  1. When client sends a message with size larger than the max-read-buffer set on the gnet server.
  2. When client sends a PING message.

I don't have deep understanding of the websocket protocol internals, but I believe this happens due to the continuation & fragmented frames? I found this reference but it's bit unclear ..

Are there any other examples to use gobwas/ws to use with a model like gnet? I believe, what I need here is to use a buffered reader in between instead of directly passing the gnet.Conn to the wsutil / ws functions.

@cristaloleg
Copy link
Collaborator

Hey, no idea about gnet, maybe @panjf2000 has some ideas.

@ehsannm
Copy link

ehsannm commented May 11, 2024

I have created a very fast and modular framework and is used in production in our company. You can check how i used gnet and gobwas/ws together.
Https://github.com/clubpay/ronykit

The related code is in std/gateways/fastws

@spy16
Copy link
Author

spy16 commented May 14, 2024

@ehsannm Thank you! This is really helpful.

Have you tried sending a websocket message that is larger than the ReadBufferCap set in gnet though? I think your implementation definitely resolves the first issue for me, since the part of reading all the control frames is in a loop.

But once you get a text/binary payload frame, if the frame size is bigger than the ReadBufferCap set on gnet, I believe, you would also run into the short-buffer error (or you might incorrectly miss a few bytes of the message, which will be read in the next OnTraffic which can corrupt all interactions after that point for that connection ).

For example, if you set ReadBufferCap to 1024, the websocket message can only be upto 1016 bytes (the remaining 8 bytes are used for the frame header)

@ehsannm
Copy link

ehsannm commented May 23, 2024

@spy16 thanks for the point, i did write a test in the testenv package and realized that you were right about the issue, i fixed it and pushed. You can check it again.

@spy16
Copy link
Author

spy16 commented May 24, 2024

Thanks, I will check this out.

I will also close this issue since it's more related to the source reader itself than this package.

@spy16 spy16 closed this as completed May 24, 2024
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

3 participants