Skip to content

Commit

Permalink
fix: Empty sync message causes error in client MessageReceiver (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor authored Aug 20, 2021
1 parent 46b5bc2 commit f9dca69
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
22 changes: 9 additions & 13 deletions packages/provider/src/MessageReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,15 @@ export class MessageReceiver {

message.writeVarUint(MessageType.Sync)

try {
const syncMessageType = readSyncMessage(
message.decoder,
message.encoder,
provider.document,
provider,
)

if (emitSynced && syncMessageType === messageYjsSyncStep2) {
provider.synced = true
}
} catch (e) {
// TODO: That shouldn’t happen … but it does. Remove the try/catch and run the tests.
const syncMessageType = readSyncMessage(
message.decoder,
message.encoder,
provider.document,
provider,
)

if (emitSynced && syncMessageType === messageYjsSyncStep2) {
provider.synced = true
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/server/src/IncomingMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Encoder,
toUint8Array,
writeVarUint,
length,
} from 'lib0/encoding'
import { MessageType } from './types'

Expand Down Expand Up @@ -47,4 +48,8 @@ export class IncomingMessage {
writeVarUint(type: MessageType) {
writeVarUint(this.encoder, type)
}

get length(): number {
return length(this.encoder)
}
}
5 changes: 4 additions & 1 deletion packages/server/src/MessageReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export class MessageReceiver {
case MessageType.Sync:
message.writeVarUint(MessageType.Sync)
this.readSyncMessage(message, connection)
connection.send(message.toUint8Array())

if (message.length > 1) {
connection.send(message.toUint8Array())
}

break
case MessageType.Awareness:
Expand Down

0 comments on commit f9dca69

Please sign in to comment.