jerluc / driftd

Drift protocol daemon
MIT License
1 stars 0 forks source link

Handle EOF panic when device is removed #10

Open jerluc opened 7 years ago

jerluc commented 7 years ago

As of this writing, when the serial device is removed after riftd starts, the main incoming packet processing loop panics, as its underlying read hits an EOF. Because this runtime panic is unhandled, this blows the whole process, without giving other goroutines time to clean up their resources.

Instead, we should handle the EOF and have it shutdown the exchange gracefully, such that we can avoid leaking any open sockets/fds.

jerluc commented 7 years ago

E.g.

2017/04/14 18:58:43 18:58:43.573 ▶ ERRO 00f Error reading incoming packet: EOF
2017/04/14 18:58:43 18:58:43.573 ▶ INFO 010 Shutting down exchange
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x52a4cc]

goroutine 7 [running]:
panic(0x5eb1a0, 0xc420012110)
    /usr/lib/go/src/runtime/panic.go:500 +0x1a1
github.com/jerluc/gobee.(*FrameBuffer).WriteFrame(0xc420013730, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/jl/dev/src/github.com/jerluc/gobee/buffer.go:25 +0x3c
github.com/jerluc/gobee.(*Mailbox).Outbox.func1(0xc420074840, 0xc4200301f0)
    /home/jl/dev/src/github.com/jerluc/gobee/mailbox.go:36 +0x78
created by github.com/jerluc/gobee.(*Mailbox).Outbox
    /home/jl/dev/src/github.com/jerluc/gobee/mailbox.go:38 +0x67