-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Don't negotiate leafnode compression over WebSockets #7969
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1646,6 +1646,14 @@ func (c *client) processLeafnodeInfo(info *Info) { | |
| } | ||
|
|
||
| func (s *Server) negotiateLeafCompression(c *client, didSolicit bool, infoCompression string, co *CompressionOpts) (bool, error) { | ||
| // WebSockets already have compression available so shouldn't negotiate | ||
| // a second layer of it. | ||
| if c.isWebsocket() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| c.mu.Lock() | ||
| c.leaf.compression = CompressionOff | ||
| c.mu.Unlock() | ||
| return false, nil | ||
|
Comment on lines
+1651
to
+1655
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This unconditional Useful? React with 👍 / 👎. |
||
| } | ||
| // Negotiate the appropriate compression mode (or no compression) | ||
| cm, err := selectCompressionMode(co.Mode, infoCompression) | ||
| if err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7652,6 +7652,55 @@ func TestLeafNodeCompressionWithOlderServer(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestLeafNodeNoCompressionWithWebsocket(t *testing.T) { | ||
| conf1 := createConfFile(t, []byte(` | ||
| port: -1 | ||
| server_name: "A" | ||
| websocket { | ||
| listen: "127.0.0.1:-1" | ||
| no_tls: true | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you accept the changes in negotiateLeafCompression(), then you would likely need a multiple-case test where you try with |
||
| leafnodes { | ||
| port: -1 | ||
| compression: "s2_fast" | ||
| } | ||
| `)) | ||
| s1, o1 := RunServerWithConfig(conf1) | ||
| defer s1.Shutdown() | ||
|
|
||
| conf2 := createConfFile(t, []byte(fmt.Sprintf(` | ||
| port: -1 | ||
| server_name: "B" | ||
| leafnodes { | ||
| remotes [ | ||
| {url: "ws://127.0.0.1:%d"} | ||
| ] | ||
| } | ||
| `, o1.Websocket.Port))) | ||
| s2, _ := RunServerWithConfig(conf2) | ||
| defer s2.Shutdown() | ||
|
|
||
| checkLeafNodeConnected(t, s2) | ||
|
|
||
| getLeafCompMode := func(s *Server) string { | ||
| var cm string | ||
| s.mu.RLock() | ||
| defer s.mu.RUnlock() | ||
| for _, l := range s.leafs { | ||
| l.mu.Lock() | ||
| cm = l.leaf.compression | ||
| l.mu.Unlock() | ||
| return cm | ||
| } | ||
| return _EMPTY_ | ||
| } | ||
| for _, s := range []*Server{s1, s2} { | ||
| if cm := getLeafCompMode(s); cm != CompressionOff { | ||
| t.Fatalf("Expected websocket leaf compression to be %q, got %q", CompressionOff, cm) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestLeafNodeCompressionAuto(t *testing.T) { | ||
| for _, test := range []struct { | ||
| name string | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should lock before
c.isWebsocket()although I do believe that it is immutable. But, as also pointed out by codex, it is not necessary that web socket connection uses their own compression (it can be disabled or negotiated as off). So I wonder, should it be instead more something like: