pitaya
pitaya copied to clipboard
agent panic: concurrent write to websocket connection
Hi, I got a panic as bellow ([email protected]):
github.com/gorilla/websocket.(*messageWriter).flushFrame(0xc000dd8df0, 0xc0002ce301, 0xc0002ce330, 0x0, 0x0, 0x0, 0xc0016de5e0) github.com/gorilla/[email protected]/conn.go:610 +0x60e github.com/gorilla/websocket.(*Conn).WriteMessage(0xc001114dc0, 0x2, 0xc0002ce330, 0x30, 0x30, 0x0, 0x0) github.com/gorilla/[email protected]/conn.go:763 +0x238 github.com/topfreegames/pitaya/acceptor.(*WSConn).Write(0xc0007f7700, 0xc0002ce330, 0x30, 0x30, 0x1, 0xfea90e, 0x7) github.com/topfreegames/[email protected]/acceptor/ws_acceptor.go:233 +0x59 github.com/topfreegames/pitaya/agent.(*Agent).write(0xc0012232c0) github.com/topfreegames/[email protected]/agent/agent.go:418 +0x26a created by github.com/topfreegames/pitaya/agent.(*Agent).Handle github.com/topfreegames/[email protected]/agent/agent.go:331 +0x66
Here is my temporary solution: func (a *Agent) write() { // clean func defer func() { if err := recover(); err != nil { logger.Log.Fatalf("Agent write panic: %v", err) } a.Close() }() ... }
github.com/gorilla/websocket.(*messageWriter).flushFrame(0xc000719d98, 0xc000568901, 0xc000568950, 0x0, 0x0, 0xc000719da0, 0x44d12c) github.com/gorilla/websocket/conn.go:610 +0x60e github.com/gorilla/websocket.(*Conn).WriteMessage(0xc001337a20, 0x2, 0xc000568950, 0x4, 0x4, 0x0, 0x0) github.com/gorilla/websocket/conn.go:763 +0x238 github.com/topfreegames/pitaya/acceptor.(*WSConn).Write(0xc000a1a2a0, 0xc000568950, 0x4, 0x4, 0x0, 0xc000568950, 0x4) github.com/topfreegames/pitaya/acceptor/ws_acceptor.go:233 +0x59 github.com/topfreegames/pitaya/agent.(*Agent).Kick(0xc0009f6d80, 0x11210a0, 0xc0001a4010, 0xe320a0, 0xc000719ee8) github.com/topfreegames/pitaya/agent/agent.go:310 +0xa9 github.com/topfreegames/pitaya/session.(*Session).Kick(0xc0009f6e40, 0x11210a0, 0xc0001a4010, 0xfd8360, 0xc0009f6e40) github.com/topfreegames/pitaya/session/session.go:319 +0x4c github.com/topfreegames/pitaya/modules.(*UniqueSession).OnUserBind(0xc000448740, 0xc000568938, 0x8, 0xc00035af00, 0x24) github.com/topfreegames/pitaya/modules/unique_session.go:53 +0xc5 github.com/topfreegames/pitaya/service.(*RemoteService).SessionBindRemote(0xc000222000, 0x11210a0, 0xc0001a4010, 0xc0012936c0, 0xc0012936c0, 0x0, 0x0) github.com/topfreegames/pitaya/service/remote.go:153 +0x91 github.com/topfreegames/pitaya/cluster.(*NatsRPCServer).processSessionBindings(0xc00023e600) github.com/topfreegames/pitaya/cluster/nats_rpc_server.go:288 +0x1b6 created by github.com/topfreegames/pitaya/cluster.(*NatsRPCServer).Init github.com/topfreegames/pitaya/cluster/nats_rpc_server.go:345 +0x40a
// Logon Request func (c *Connector) Logon(ctx context.Context, ...) (..., error) { ...... oldsession := session.GetSessionByUID(uid) if oldsession != nil { oldsession.Kick(ctx) // panic here oldss.Close() } ...... }
Sometimes we got panic as bellow: panic - pitaya/dispatch: methodName=Logon panicData=concurrent write to websocket connection stackTrace="goroutine 67 [running]:\nruntime/debug.Stack(0xc0004b1268, 0xe320a0, 0x10eea00)\n\tD:/Go/src/runtime/debug/stack.go:24 +0x9f\ngithub.com/topfreegames/pitaya/util.Pcall.func1(0xc000d64fc0, 0x3, 0x4, 0xda2e8b, 0x5, 0x0, 0x0, 0x1132a60, 0xc0001f0080, 0xc0001f0080, ...)\n\tgithub.com/topfreegames/[email protected]/util/util.go:69 +0x76\npanic(0xe320a0, 0x10eea00)\n\tD:/Go/src/runtime/panic.go:969 +0x1b9\ngithub.com/gorilla/websocket.(*messageWriter).flushFrame(0xc0004b1560, 0xc0007e0501, 0xc0007e05c8, 0x0, 0x0, 0xc0004b1568, 0x44d12c)\n\tgithub.com/gorilla/[email protected]/conn.go:610 +0x60e\ngithub.com/gorilla/websocket.(*Conn).WriteMessage(0xc00016a160, 0x2, 0xc0007e05c8, 0x4, 0x4, 0x0, 0x0)\n\tgithub.com/gorilla/[email protected]/conn.go:763 +0x238\ngithub.com/topfreegames/pitaya/acceptor.(*WSConn).Write(0xc00035e0e0, 0xc0007e05c8, 0x4, 0x4, 0x0, 0xc0007e05c8, 0x4)\n\tgithub.com/topfreegames/[email protected]/acceptor/ws_acceptor.go:233 +0x59\ngithub.com/topfreegames/pitaya/agent.(*Agent).Kick(0xc000f8f5c0, 0x1121080, 0xc0014200f0, 0xe320a0, 0xc0004b1708)\n\tgithub.com/topfreegames/[email protected]/agent/agent.go:310 +0xa9\ngithub.com/topfreegames/pitaya/session.(*Session).Kick(0xc000f8f680, 0x1121080, 0xc0014200f0, 0xfd82e0, 0xc000f8f680)\n\tgithub.com/topfreegames/[email protected]/session/session.go:319 +0x4c\nwuta-go/gate/services.(*Connector).Logon(0xc00059ebd0, 0x1121080, 0xc0014200f0, 0xc000da6bd0, 0x0, 0x0, 0x0)\n\tF:/work_dir/GoPath/src/wuta-go/gate/services/connector.go:194 +0x50d\nreflect.Value.call(0xc0001f0080, 0xc0000b72a0, 0x13, 0xfe74e2, 0x4, 0xc000d64fc0, 0x3, 0x4, 0x203000, 0x203000, ...)\n\tD:/Go/src/reflect/value.go:476 +0x8c7\nreflect.Value.Call(0xc0001f0080, 0xc0000b72a0, 0x13, 0xc000d64fc0, 0x3, 0x4, 0xc000b0daf0, 0x7f52ead3f190, 0x58)\n\tD:/Go/src/reflect/value.go:337 +0xb9\ngithub.com/topfreegames/pitaya/util.Pcall(0xda2e8b, 0x5, 0x0, 0x0, 0x1132a60, 0xc0001f0080, 0xc0001f0080, 0xc0000b72a0, 0x13, 0x3, ...)\n\tgithub.com/topfreegames/[email protected]/util/util.go:82 +0x125\ngithub.com/topfreegames/pitaya/service.processHandlerMessage(0x1121080, 0xc0014200f0, 0xc001420030, 0x1116000, 0x176a1f8, 0xc000d81c80, 0xc000c0c008, 0x48, 0x48, 0xe30ba0, ...)\n\tgithub.com/topfreegames/[email protected]/service/util.go:188 +0x6f1\ngithub.com/topfreegames/pitaya/service.(*HandlerService).localProcess(0xc0003383c0, 0x1121080, 0xc001420000, 0xc000d815c0, 0xc001420030, 0xc000173a00)\n\tgithub.com/topfreegames/[email protected]/service/handler.go:317 +0xe5\ngithub.com/topfreegames/pitaya/service.(*HandlerService).Dispatch(0xc0003383c0, 0x14)\n\tgithub.com/topfreegames/[email protected]/service/handler.go:128 +0x486\ncreated by github.com/topfreegames/pitaya.listen\n\tgithub.com/topfreegames/[email protected]/app.go:455 +0x187\n" [31mrequestId[0m=8fa17f3e-a679-445d-80c3-20f249cbc740
@felipejfc no one care about this issue?
do you mind sending a PR? at wildlife we don't use the Websocket acceptor, only raw TCP, this is why this is not a priority for us to fix
I have the same issue