Skip to content

[ERR_STREAM_DESTROYED] seems sharedb is not closing connections #282

Closed
@sionzee

Description

@sionzee

Hey! I just upgraded to teamwork streamer.

ShareDb: 1.0.0-beta.21
sharedb-mongo: 1.0.0-beta.8
reconnecting-websocket: 4.1.10
@teamwork/websocket-json-stream: 2.0.0
rich-text: 3.1.0
ws: 6.2.1

node: 11.13.0
npm: 6.9.0

When I open page, everything is working right. Submitting op works without issues. Then I refresh the page and after first submitOp it throws an error.

Error what is crashing node server:

Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
    at doWrite (_stream_writable.js:411:19)
    at writeOrBuffer (_stream_writable.js:399:5)
    at WebSocketJSONStream.Writable.write (_stream_writable.js:299:11)
    at Agent.send (/projects/alganep/server/node_modules/sharedb/lib/agent.js:165:15)
    at Agent._sendOp (/projects/alganep/server/node_modules/sharedb/lib/agent.js:181:8)
    at OpStream.<anonymous> (/projects/alganep/server/node_modules/sharedb/lib/agent.js:103:11)
    at OpStream.emit (events.js:193:13)
    at addChunk (_stream_readable.js:296:12)
    at readableAddChunk (_stream_readable.js:277:11)
    at OpStream.Readable.push (_stream_readable.js:232:10)

Last data what reached server before crash (immediately after it)

bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: WebSocket {__zone_symbol__openfalse: null, __zone_symbol__closefalse: null, __zone_symbol__messagefalse: null, __zone_symbol__errorfalse: null, url: "ws://alganep:7000/", …}
data: "{"src":"1c7ce151b76c9abff41d499afc4640db","seq":1,"v":85,"a":"op","c":"texts","d":"17435_Tester"}"
defaultPrevented: false
eventPhase: 0
isTrusted: true
lastEventId: ""
origin: "ws://alganep:7000"
path: []
ports: []
returnValue: true
source: null
srcElement: WebSocket {__zone_symbol__openfalse: null, __zone_symbol__closefalse: null, __zone_symbol__messagefalse: null, __zone_symbol__errorfalse: null, url: "ws://alganep:7000/", …}
target: WebSocket {__zone_symbol__openfalse: null, __zone_symbol__closefalse: null, __zone_symbol__messagefalse: null, __zone_symbol__errorfalse: null, url: "ws://alganep:7000/", …}
timeStamp: 11002.040000050329
type: "message"
userActivation: null
decoded: (...)
deepCopy: (...)
encoded: (...)
__proto__: MessageEvent
index.js?9e40:25 

UPDATE

I find out for every refresh is error duplicated.
So when I open page first time then the error comes only once.
When I refresh the page 10 times and let it connect everytime to ShareDb. Then the error is printed 10 times.

Seems like memory-leak?

I attached listener for stream#close and it is called everytime.
eg.:

// Connect any incoming WebSocket connection to ShareDB
	const webSocket = new WebSocket.Server({server: server})
	webSocket.on("connection", function (ws, req) {
		console.warn("Incoming websocket connection")
		const stream = new WebSocketJSONStream(ws)
		stream.on('error', error => {
			console.log("----------------------------------------")
			console.log(error)
		})
		stream.on("data", message => {
			console.log("data", message)
		})
		stream.on("close", () => {
			console.log("stream closed...")
		})
		sharedb.listen(stream)
	})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions