server: make sure that OnFrame() is never called after OnSessionClose()

This commit is contained in:
aler9
2021-05-16 21:30:13 +02:00
parent c6ff1e0d02
commit ea6138c282
2 changed files with 8 additions and 0 deletions

View File

@@ -61,6 +61,9 @@ type ServerConn struct {
// in
sessionRemove chan *ServerSession
// out
done chan struct{}
}
func newServerConn(
@@ -75,6 +78,7 @@ func newServerConn(
ctx: ctx,
ctxCancel: ctxCancel,
sessionRemove: make(chan *ServerSession),
done: make(chan struct{}),
}
s.wg.Add(1)
@@ -104,6 +108,7 @@ func (sc *ServerConn) zone() string {
func (sc *ServerConn) run() {
defer sc.s.wg.Done()
defer close(sc.done)
if h, ok := sc.s.Handler.(ServerHandlerOnConnOpen); ok {
h.OnConnOpen(&ServerHandlerOnConnOpenCtx{

View File

@@ -332,6 +332,9 @@ func (ss *ServerSession) run() {
for sc := range ss.conns {
if sc == ss.tcpConn {
sc.Close()
// make sure that OnFrame() is never called after OnSessionClose()
<-sc.done
}
select {