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
10 changes: 10 additions & 0 deletions packages/common/src/CloseEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ export interface CloseEvent {
reason: string,
}

/**
* The server is terminating the connection because a data frame was received
* that is too large.
* See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
*/
export const MessageTooBig: CloseEvent = {
code: 1009,
reason: 'Message Too Big',
}

/**
* The server successfully processed the request, asks that the requester reset
* its document view, and is not returning any content.
Expand Down
7 changes: 6 additions & 1 deletion packages/provider/src/HocuspocusProviderWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as url from 'lib0/url'
import type { MessageEvent } from 'ws'
import { retry } from '@lifeomic/attempt'
import {
Forbidden, Unauthorized, WsReadyStates,
Forbidden, MessageTooBig, Unauthorized, WsReadyStates,
} from '@hocuspocus/common'
import { Event } from 'ws'
import EventEmitter from './EventEmitter'
Expand Down Expand Up @@ -425,6 +425,11 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
}
}

if (event.code === MessageTooBig.code) {
console.warn(`[HocuspocusProvider] Connection closed with status MessageTooBig: ${event.reason}`)
this.shouldConnect = false
}

if (this.connectionAttempt) {
// That connection attempt failed.
this.rejectConnectionAttempt()
Expand Down