apache / dubbo-getty

a netty like asynchronous network I/O library based on tcp/udp/websocket; a bidirectional RPC framework based on JSON/Protobuf; a microservice framework based on zookeeper/etcd
Apache License 2.0
216 stars 69 forks source link

Concurrency issues can occur when using this framework for websocket transfers #120

Open chenbaoding2818 opened 1 month ago

chenbaoding2818 commented 1 month ago

WARNING: DATA RACE Read at 0x00c0004610f8 by goroutine 14: github.com/gorilla/websocket.(Conn).beginMessage() /Users/vendor/github.com/gorilla/websocket/conn.go:472 +0x65 github.com/gorilla/websocket.(Conn).WriteMessage() /Users/vendor/github.com/gorilla/websocket/conn.go:757 +0xf9 github.com/apache/dubbo-getty.(gettyWSConn).writePing() /Users/vendor/github.com/apache/dubbo-getty/connection.go:627 +0x68 github.com/apache/dubbo-getty.heartbeat.func1() /Users/vendor/github.com/apache/dubbo-getty/session.go:519 +0x6d github.com/apache/dubbo-getty.heartbeat() /Users/vendor/github.com/apache/dubbo-getty/session.go:533 +0x167 github.com/dubbogo/gost/time.(TimerWheel).run() /Users/vendor/github.com/dubbogo/gost/time/timer.go:281 +0x2b9 github.com/dubbogo/gost/time.NewTimerWheel.func1() /Users/vendor/github.com/dubbogo/gost/time/timer.go:216 +0x4a4

Previous write at 0x00c0004610f8 by goroutine 7976: github.com/gorilla/websocket.(messageWriter).endMessage() /Users/vendor/github.com/gorilla/websocket/conn.go:539 +0xcd github.com/gorilla/websocket.(messageWriter).flushFrame() /Users/vendor/github.com/gorilla/websocket/conn.go:626 +0xb85 github.com/gorilla/websocket.(Conn).WriteMessage() /Users/vendor/github.com/gorilla/websocket/conn.go:763 +0x1d0 github.com/apache/dubbo-getty.(gettyWSConn).send() /Users/vendor/github.com/apache/dubbo-getty/connection.go:618 +0x117 github.com/apache/dubbo-getty.(session).WritePkg() /Users/vendor/github.com/apache/dubbo-getty/session.go:408 +0x3a7 server/common/net.(Session).Write()

chenbaoding2818 commented 1 month ago

image image 当心跳与业务同时WriteMessage方法时,会导致c.writer存在竞态问题

AlexStocks commented 1 month ago

Will you submit a PR to solve this problem?

FoghostCn commented 1 month ago

it seems like heartbeat not obtain packetLock cause the problem

https://github.com/apache/dubbo-getty/blob/6a6e1d13bf1f5bea59d43fb0c56194d55b8fd5a5/session.go#L513-L538

AlexStocks commented 1 month ago

@chenbaoding2818 we have fixed this bug. Would you please check it by v1.4.12?