Skip to content

Commit

Permalink
fix: Fix panic due to send on closed channel
Browse files Browse the repository at this point in the history
```
2025-01-23T12:19:46+08:00 |INFO| New session: bf1be06db4b7c04cb951e5cb90e60f3b
panic: send on closed channel

goroutine 8 [running]:
main.(*user).WriteMsg(0xc000342140, 0x1, {0xc000124050, 0x41, 0x50})
        /mnt/wsl/work/rttys/user.go:52 +0x8b
main.userLoginAck(0x0, {0xf83100, 0xc000342140})
        /mnt/wsl/work/rttys/user.go:75 +0xc9
main.(*broker).run(0xc000270c80)
        /mnt/wsl/work/rttys/broker.go:212 +0xd91
created by main.runRttys in goroutine 1
        /mnt/wsl/work/rttys/main.go:86 +0x595
exit status 2
```

Run this script to reproduce:
```

local websocket = require 'eco.websocket'

local ws, err = websocket.connect('ws://127.0.0.1:5913/connect/test')
if not ws then
    print('failed to connect: ' .. err)
    return
end

os.exit()
```

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Jan 23, 2025
1 parent 2540677 commit 837cb8b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func (br *broker) run() {
if dev, ok := br.devices[devid]; ok {
sid := utils.GenUniqueID("sid")

c.(*user).sid = sid

s := &session{
dev: dev,
user: c,
Expand Down Expand Up @@ -206,9 +208,6 @@ func (br *broker) run() {
} else {
atomic.StoreUint32(&s.confirmed, 1)

u := s.user.(*user)
u.sid = msg.sid

userLoginAck(loginErrorNone, s.user)
}
}
Expand Down

0 comments on commit 837cb8b

Please # to comment.