Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/events/websockets/websocket_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func (wc *websocketConnection) protocolError(err error) {
}

func (wc *websocketConnection) send(msg interface{}) error {
if wc.closed {
return i18n.NewError(wc.ctx, i18n.MsgWSClosed)
}
select {
case wc.sendMessages <- msg:
return nil
Expand Down
24 changes: 24 additions & 0 deletions internal/events/websockets/websockets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,3 +606,27 @@ func TestDispatchAutoAck(t *testing.T) {
assert.NoError(t, err)
cbs.AssertExpectations(t)
}

func TestWebsocketSendAfterClose(t *testing.T) {
cbs := &eventsmocks.Callbacks{}
ws, wsc, cancel := newTestWebsockets(t, cbs)
defer cancel()

subscribedConn := make(chan string, 1)
cbs.On("EphemeralSubscription",
mock.MatchedBy(func(s string) bool {
subscribedConn <- s
return true
}),
"ns1", mock.Anything, mock.Anything).Return(nil)

err := wsc.Send(context.Background(), []byte(`{"type":"start","namespace":"ns1","ephemeral":true}`))
assert.NoError(t, err)

connID := <-subscribedConn
connection := ws.connections[connID]
connection.wsConn.Close()
<-connection.senderDone
err = connection.send(map[string]string{"foo": "bar"})
assert.Regexp(t, "FF10290", err)
}
1 change: 1 addition & 0 deletions internal/i18n/en_translations.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,5 @@ var (
MsgInvalidMessageType = ffm("FF10287", "Invalid message type - allowed types are %s", 400)
MsgNoUUID = ffm("FF10288", "Field '%s' must not be a UUID", 400)
MsgFetchDataDesc = ffm("FF10289", "Fetch the data and include it in the messages returned", 400)
MsgWSClosed = ffm("FF10290", "Websocket closed")
)