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

Push channel JSON over binary #5815

Open
josevalim opened this issue May 17, 2024 · 1 comment
Open

Push channel JSON over binary #5815

josevalim opened this issue May 17, 2024 · 1 comment

Comments

@josevalim
Copy link
Member

Both Bandit and Cowboy validate UTF-8 of text frames, per spec, but Channels push JSON which are also validated against UTF-8. Therefore, I suggest we use a binary frame for pushing JSON.

Our serializers already handle binary frames, but they always start with the bytes 0, 1, and 2. So there is no clash with JSON and we can start sending JSON over binaries frames without introducing a new serializer version. However, we may want to have a flag on the client that forces it over text instead for those who for some reason need to run against other serializers.

/cc @mtrudel

@mtrudel
Copy link
Member

mtrudel commented May 17, 2024

Good catch! As you know, UTF-8 validation is a surprisingly expensive operation and is usually near the top of profiling analysis of Bandit's WebSocket stack. It's an expensive thing to double up on for sure.

I agree that binary probably makes the most sense here (the spec is pretty loose about which one to use where; binary is mostly considered a simpler 'all bets are off' option that would apply well here). Absent that, both Bandit and Cowboy have flags to disable UTF-8 validation.

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

No branches or pull requests

2 participants