Skip to content

Commit 462a87f

Browse files
authored
fix: Do not retry connection if data is too large (#586)
* Do not retry connection if data is too large * lint * Remove yarn.lock
1 parent 7c38bd7 commit 462a87f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/common/src/CloseEvents.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ export interface CloseEvent {
33
reason: string,
44
}
55

6+
/**
7+
* The server is terminating the connection because a data frame was received
8+
* that is too large.
9+
* See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
10+
*/
11+
export const MessageTooBig: CloseEvent = {
12+
code: 1009,
13+
reason: 'Message Too Big',
14+
}
15+
616
/**
717
* The server successfully processed the request, asks that the requester reset
818
* its document view, and is not returning any content.

packages/provider/src/HocuspocusProviderWebsocket.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as url from 'lib0/url'
44
import type { MessageEvent } from 'ws'
55
import { retry } from '@lifeomic/attempt'
66
import {
7-
Forbidden, Unauthorized, WsReadyStates,
7+
Forbidden, MessageTooBig, Unauthorized, WsReadyStates,
88
} from '@hocuspocus/common'
99
import { Event } from 'ws'
1010
import EventEmitter from './EventEmitter'
@@ -425,6 +425,11 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
425425
}
426426
}
427427

428+
if (event.code === MessageTooBig.code) {
429+
console.warn(`[HocuspocusProvider] Connection closed with status MessageTooBig: ${event.reason}`)
430+
this.shouldConnect = false
431+
}
432+
428433
if (this.connectionAttempt) {
429434
// That connection attempt failed.
430435
this.rejectConnectionAttempt()

0 commit comments

Comments
 (0)