Skip to content

Commit

Permalink
fix: keep client default client read limit when realtime doesn't specify
Browse files Browse the repository at this point in the history
This is mostly for internal purposes, where we have rate limits of 0 (read: unlimited).

When 0 is received from realtime, the SDK should continue with its existing defaults.
  • Loading branch information
AndyTWF committed Feb 1, 2024
1 parent cc9e260 commit c493707
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions ably/realtime_channel_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,47 @@ func TestRealtimeChannel_ShouldSetProvidedReadLimit(t *testing.T) {
assert.Equal(t, int64(2048), client.Connection.ReadLimit())
}

func TestRealtimeChannel_SetsNoLimitIfServerNoLimits(t *testing.T) {
// Mock out the dial
dial := DialFunc(func(p string, url *url.URL, timeout time.Duration) (ably.Conn, error) {
return connMock{
SendFunc: func(m *ably.ProtocolMessage) error {
return nil
},
ReceiveFunc: func(deadline time.Time) (*ably.ProtocolMessage, error) {
connDetails := ably.ConnectionDetails{
ClientID: "id1",
ConnectionKey: "foo",
MaxFrameSize: 12,
MaxInboundRate: 14,
MaxMessageSize: 0,
ConnectionStateTTL: ably.DurationFromMsecs(time.Minute * 2),
MaxIdleInterval: ably.DurationFromMsecs(time.Second),
}

return &ably.ProtocolMessage{
Action: ably.ActionConnected,
ConnectionID: "connection-id-1",
ConnectionDetails: &connDetails,
}, nil
},
CloseFunc: func() error {
return nil
},
}, nil
})

_, c := ablytest.NewRealtime(ably.WithDial(dial))

// Wait for a little bit for things to settle
time.Sleep(1 * time.Second)

// Check that the connection read limit is the default - due to websocket.go
// Only allowing the value to be set if the connection is a certain type
// We'll just check -1 here
assert.Equal(t, int64(-1), c.Connection.ReadLimit())
}

func TestRealtimeChannel_ShouldReturnErrorIfReadLimitExceeded(t *testing.T) {
app, client1 := ablytest.NewRealtime(ably.WithEchoMessages(false))
defer safeclose(t, ablytest.FullRealtimeCloser(client1), app)
Expand Down
2 changes: 1 addition & 1 deletion ably/realtime_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func (c *Connection) eventloop() {
c.connStateTTL = connDetails.ConnectionStateTTL
// Spec RSA7b3, RSA7b4, RSA12a
c.auth.updateClientID(connDetails.ClientID)
if !c.isReadLimitSetExternally {
if !c.isReadLimitSetExternally && connDetails.MaxMessageSize > 0 {
c.readLimit = connDetails.MaxMessageSize // set MaxMessageSize limit as per TO3l8
}
}
Expand Down

0 comments on commit c493707

Please sign in to comment.