Skip to content

Commit

Permalink
fix: Do not retry connection if data is too large (#586)
Browse files Browse the repository at this point in the history
* Do not retry connection if data is too large

* lint

* Remove yarn.lock
  • Loading branch information
tommoor authored Apr 23, 2023
1 parent 7c38bd7 commit 462a87f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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

0 comments on commit 462a87f

Please sign in to comment.