Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: send on closed channel #111

Open
houzy opened this issue Jul 6, 2022 · 3 comments
Open

panic: send on closed channel #111

houzy opened this issue Jul 6, 2022 · 3 comments

Comments

@houzy
Copy link

houzy commented Jul 6, 2022

Environment

rtty

  • arch: arm64
  • os: Debian 10
  • version: v8.0.0

rttys

  • arch: amd64
  • os: alpine
  • version: v4.0.1/v4.0.2

Description

服务端时不时崩溃重启,后面贴上两个报错信息

goroutine 49 [running]:
main.(*device).WriteMsg(0xc0016e23f0, 0x0, {0xc0027b1e40, 0x3, 0xb?})
        /home/runner/work/rttys/rttys/device.go:130 +0xff
main.(*broker).run(0xc000694000)
        /home/runner/work/rttys/rttys/broker.go:97 +0x755
created by main.runRttys
        /home/runner/work/rttys/rttys/main.go:72 +0x869
panic: send on closed channel

goroutine 14 [running]:
main.(*device).WriteMsg(0xc000b8a6c0, 0x0, {0xc000b59bf0, 0x3, 0x2?})
        /home/runner/work/rttys/rttys/device.go:130 +0xff
main.(*broker).run(0xc0003fb040)
        /home/runner/work/rttys/rttys/broker.go:97 +0x755
created by main.runRttys
        /home/runner/work/rttys/rttys/main.go:72 +0x869
panic: send on closed channel
@houzy
Copy link
Author

houzy commented Nov 8, 2022

通过加了一些打印信息,发现这个问题是 device.go 的 func (dev *device) WriteMsg(typ int, data []byte) { 函数调用 dev.send <- append(b, data...) 的时候,dev.send 这个通道已经被关闭了,我在这个函数调用的地方加了一个判断规避这个问题,在调用通道前,先判断这个连接是不是已经断开了,但是我不确定这个解决办法是不是完美没有其他影响:

func (dev *device) WriteMsg(typ int, data []byte) {
	if atomic.LoadUint32(&dev.closed) == 1 {
		return
	}
        ......

@zhaojh329
Copy link
Owner

是在传输文件的时候崩溃的吗?

@houzy
Copy link
Author

houzy commented Nov 15, 2022

应该不是传输文件的时候崩溃,没有做传文件这样的操作

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants