Skip to content

Commit 6fb1e45

Browse files
committed
Recover panic in udev goroutine
uevent.NewDecoder uses bufio.ReadString() that is blocking until data is available. When booster switches to the userspace it needs to close all file descriptors including the udev one. Unfortunately there is no clear way to break the bufio.ReadString() blocking. Attempt to close the fd causes panic inside the bufio.(*Reader).fill() function. To prevent the app crash we just recover from panic in the udev goroutine. Issue #22 Issue #31 Issue #153
1 parent e735cf4 commit 6fb1e45

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Diff for: init/udev.go

+9
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ func validDmEvent(ev *uevent.Uevent) bool {
6666
var udevReader io.ReadCloser
6767

6868
func udevListener() error {
69+
defer func() {
70+
// uevent.NewDecoder uses bufio.ReadString() that is blocking. If we try to close the underlying udev file descriptor
71+
// while bufio tries to read from it then bufio panics. See issues #22, #31 and #153
72+
// There is no clear way to prevent the panic so we just recover from it here and then safely exit the goroutine.
73+
if r := recover(); r != nil {
74+
warning("recovered udevListener panic: %v", r)
75+
}
76+
}()
77+
6978
var err error
7079
udevReader, err = uevent.NewReader()
7180
if err != nil {

0 commit comments

Comments
 (0)