Skip to content

Commit

Permalink
@uppy/companion: handle ws 'error' event (#5167)
Browse files Browse the repository at this point in the history
to prevent companion from crashing with RangeError: Max payload size exceeded
  • Loading branch information
mifi committed May 15, 2024
1 parent 86e2e67 commit 1ac7f9c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/@uppy/companion/src/server/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ module.exports = (server) => {
emitter().emit(`connection:${token}`)
emitter().on(token, send)

ws.on('error', (err) => {
// https://github.com/websockets/ws/issues/1543
// https://github.com/websockets/ws/blob/b73b11828d166e9692a9bffe9c01a7e93bab04a8/test/receiver.test.js#L936
if (err?.name === 'RangeError' && 'code' in err && err.code === 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH') {
logger.error('WebSocket message too large', 'websocket.error', shortenToken(token))
} else {
logger.error(err, 'websocket.error', shortenToken(token))
}
})

ws.on('message', (jsonData) => {
const data = JSON.parse(jsonData.toString())
// whitelist triggered actions
Expand Down

0 comments on commit 1ac7f9c

Please sign in to comment.