-
Notifications
You must be signed in to change notification settings - Fork 2
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
consrv does not gracefully handle disappearing / re-appearing serial device #3
Comments
A pragmatic workaround for this is to enable logtostdout (see PR #5) and make consrv log.Fatalf when reading EOF: diff --git i/cmd/consrv/main.go w/cmd/consrv/main.go
index da918a0..18cef58 100644
--- i/cmd/consrv/main.go
+++ w/cmd/consrv/main.go
@@ -119,6 +119,10 @@ func main() {
if err := scanner.Err(); err != nil {
ll.Printf("copying serial to stdout: %v", err)
}
+ // io.EOF (not considered an error by scanner.Err()) is
+ // unexpected here, as we expect an infinite serial
+ // stream. Encountering io.EOF means the device has disappeared.
+ log.Fatalf("device disappeared: %s", d.Name)
}()
}
}
When unplugging the serial adapter, consrv starts crashlooping until the adapter is plugged back in. Obviously this is only doable when you have precisely 1 serial adapter you care about, otherwise the failure of one results in all other adapters being unavailable, too. |
In my setup, for whichever reason, the USB-to-serial adapter occasionally drops off the USB bus and comes back as
ttyUSB1
instead ofttyUSB0
:I don’t know yet if this correlates to any specific trigger (perhaps rebooting my router?), but it happens frequently enough to be noticeable.
This behavior can be reproduced by physically un-plugging the USB-to-serial adapter and plugging it back in.
On the Go side, the symptom is that Read() returns an io.EOF error.
Currently, consrv connections just hang indefinitely until you send a byte, which triggers a write to the
ttyUSB0
device, which triggers awrite /dev/ttyUSB1: input/output error
that then closes the SSH session.There are a number of things subtly wrong that result in the silent swallowing of the error. I can send a PR that addresses enough of them to make the SSH session close immediately when un-plugging the adapter.
What’s still left to be done is closing the mux device and underlying serial port, and then re-opening it on the next connection.
The text was updated successfully, but these errors were encountered: