nurdism / neko

A self hosted virtual browser (rabb.it clone) that runs in docker.
Apache License 2.0
2.03k stars 185 forks source link

[BUG] panic: concurrent write to websocket connection #27

Closed nurdism closed 4 years ago

nurdism commented 4 years ago

Describe the bug Crash

To Reproduce Unknown

Expected behavior No Crash

Screenshots N/A

Client Log: N/A

Server Log:

12:04AM INF signaling state changed to have-remote-offer module=webrtc subsystem=pc
12:04AM DBG Started agent: isControlling? false, remoteUfrag: "pu0v", remotePwd: "S+ffm84/u9k+xCBKT8E1AxM8" module=webrtc subsystem=ice
12:04AM INF Setting new connection state: Checking module=webrtc subsystem=ice
12:04AM INF ICE connection state changed: checking module=webrtc subsystem=pc
12:04AM INF signaling state changed to stable module=webrtc subsystem=pc
12:04AM INF Setting new connection state: Failed module=webrtc subsystem=ice
12:04AM INF ICE connection state changed: failed module=webrtc subsystem=pc
12:04AM INF peer connection state changed: failed module=webrtc subsystem=pc
12:04AM INF peer disconnected id=xJnMxloXoYzSzlOOE36rQ6uCwqynJo5j module=webrtc
12:04AM DBG read message error error="read tcp 0.0.0.0:8080->0.0.0.0:29448: use of closed network connection" module=websocket
12:04AM DBG handle socket ending address=0.0.0.0:29448 module=websocket
12:04AM DBG session destroyed id=xJnMxloXoYzSzlOOE36rQ6uCwqynJo5j module=webrtc
12:04AM DBG session destroyed id=xJnMxloXoYzSzlOOE36rQ6uCwqynJo5j module=webrtc
12:04AM DBG session ended address=0.0.0.0:29448 module=websocket session=xJnMxloXoYzSzlOOE36rQ6uCwqynJo5j
panic: concurrent write to websocket connection

goroutine 1572 [running]:
github.com/gorilla/websocket.(*messageWriter).flushFrame(0xc00009da70, 0xc0.0.0.0, 0x0, 0x0, 0x0, 0x7efed931bb28, 0x0)
    /go/pkg/mod/github.com/gorilla/websocket@v1.4.1/conn.go:610 +0x612
github.com/gorilla/websocket.(*messageWriter).Close(0xc00009da70, 0x0, 0xc00063dab0)
    /go/pkg/mod/github.com/gorilla/websocket@v1.4.1/conn.go:724 +0x62
github.com/gorilla/websocket.(*Conn).beginMessage(0xc0.0.0.0, 0xc0.0.0.0, 0x1, 0x0, 0x0)
    /go/pkg/mod/github.com/gorilla/websocket@v1.4.1/conn.go:473 +0x284
github.com/gorilla/websocket.(*Conn).NextWriter(0xc0.0.0.0, 0x1, 0x0, 0x0, 0x0, 0x0)
    /go/pkg/mod/github.com/gorilla/websocket@v1.4.1/conn.go:513 +0x53
github.com/gorilla/websocket.(*Conn).WriteJSON(0xc0.0.0.0, 0xb10360, 0xc0.0.0.0, 0.0.0.0, 0xc0002bc9c0)
    /go/pkg/mod/github.com/gorilla/websocket@v1.4.1/json.go:24 +0x49
n.eko.moe/neko/internal/websocket.(*WebSocket).Send(0xc0002d6cc0, 0xb10360, 0xc0.0.0.0, 0x0, 0x0)
    /workspace/server/internal/websocket/socket.go:28 +0x48
n.eko.moe/neko/internal/session.(*Session).Send(...)
    /workspace/server/internal/session/session.go:100
n.eko.moe/neko/internal/session.(*SessionManager).Brodcast(0xc0.0.0.0, 0xb10360, 0xc0.0.0.0, 0x0, 0x0, 0x0, 0xbaee26)
    /workspace/server/internal/session/manager.go:127 +0x121
n.eko.moe/neko/internal/websocket.(*MessageHandler).SessionDestroyed(0xc0.0.0.0, 0xc0004dc4e0, 0x20, 0xc0.0.0.0, 0xbaee26)
    /workspace/server/internal/websocket/session.go:68 +0x12a
n.eko.moe/neko/internal/websocket.(*WebSocketHandler).Start.func3(0xc0004dc4e0, 0x20)
    /workspace/server/internal/websocket/websocket.go:73 +0x4e
n.eko.moe/neko/internal/session.(*SessionManager).OnDestroy.func1(0xc0.0.0.0, 0x1, 0x1)
    /workspace/server/internal/session/manager.go:174 +0x58
github.com/kataras/go-events.(*emmiter).Emit(0xc0.0.0.0, 0xba940b, 0x9, 0xc0.0.0.0, 0x1, 0x1)
    /go/pkg/mod/github.com/kataras/go-events@v0.0.2/events.go:148 +0xbb
n.eko.moe/neko/internal/session.(*SessionManager).Destroy(0xc0.0.0.0, 0xc0004dc4e0, 0x20, 0xc0003ace20, 0x12)
    /workspace/server/internal/session/manager.go:105 +0x14b
n.eko.moe/neko/internal/websocket.(*MessageHandler).Disconnected(...)
    /workspace/server/internal/websocket/handler.go:44
n.eko.moe/neko/internal/websocket.(*WebSocketHandler).handle.func1.1(0xc0005ea2d0, 0xc0.0.0.0, 0xc0.0.0.0, 0xc0004dc4e0, 0x20)
    /workspace/server/internal/websocket/websocket.go:221 +0xfb
n.eko.moe/neko/internal/websocket.(*WebSocketHandler).handle.func1(0xc0005ea2d0, 0xc0.0.0.0, 0xc0.0.0.0, 0xc0004dc4e0, 0x20, 0xc0.0.0.0, 0xc0.0.0.0)
    /workspace/server/internal/websocket/websocket.go:237 +0x1f3
created by n.eko.moe/neko/internal/websocket.(*WebSocketHandler).handle
    /workspace/server/internal/websocket/websocket.go:217 +0x109