Skip to content

panic: send on closed channel #461

@wubie052

Description

@wubie052

version:2.11.1 --> 2,11,14
latest and correct version:2.11.11

hi,commit(#447) seems to have triggered a new error. Now, when I use Ctrl+C to close the application in Windows, an error message appears: panic: send on closed channel.

Reason:Usually, signal channels are registered by signal.notify and should not be manually closed.
signal.Notify doesn't care whether the channel is closed or not, but if you range this channel elsewhere, it will cause an early exit.
A more reasonable approach is: Do not close the signal channel unless you have full control over its lifecycle.

close(app.sgChan)
Image

Now, when I repeatedly execute Ctrl+C in Windows to close an application (note that a single input of Ctrl+C does not result in an error, but in version 2.11.1, even multiple inputs of Ctrl+C can correctly close it), an error occurs:

panic: send on closed channel
goroutine 14 [running]:
os/signal.process({0x22c2338, 0x2f061f0})
C:/Users/Admin/.g/go/src/os/signal/signal.go:245 +0x1a5
os/signal.loop()
C:/Users/Admin/.g/go/src/os/signal/signal_unix.go:23 +0x29
created by os/signal.Notify.func1.1 in goroutine 1
C:/Users/Admin/.g/go/src/os/signal/signal.go:151 +0x1f
exit status 2

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