Skip to content

客户端websocket退出房间后,有时候服务端会崩溃 #2

@saner-qu

Description

@saner-qu

崩溃的地方在main.go User.OnEvent,原因是data.(*common.DataFrame[any]).Value为nil
原代码:
func (u *User) OnEvent(event any) { switch v := event.(type) { case *track.Data: u.AddTrack(v) go v.Play(u.IO, func(data any) error { u.writeLock.Lock() defer u.writeLock.Unlock() return wsutil.WriteServerText(u.Conn, data.(*common.DataFrame[any]).Value.([]byte)) }) default: u.Subscriber.OnEvent(event) } }
修改代码:
在defer u.writeLock.Unlock()下面增加:
if data.(*common.DataFrame[any]).Value == nil { return nil }

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