Skip to content

Commit

Permalink
lxd/instance/drivers: Handle websocket closing
Browse files Browse the repository at this point in the history
When the VM disconnects due to a stop/reboot, the error is a `connection reset by peer` instead of a EOF, so this helps handle this error.

Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Sep 3, 2024
1 parent fae7cbc commit 5f337b4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lxd/instance/drivers/driver_qemu_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"io"
"strconv"
"strings"
"syscall"

"golang.org/x/sys/unix"

Expand Down Expand Up @@ -80,7 +82,9 @@ func (c *qemuCmd) Wait() (int, error) {
// Error of type EOF indicates the session ended unexpectedly,
// so we inform the client of the disconnection with a more
// descriptive message.
if errors.Is(err, io.EOF) {
// VMs can also disconnect due to a reboot/stop, so we handle
// these disconnections errors similarly.
if errors.Is(err, io.EOF) || strings.Contains(err.Error(), syscall.ECONNRESET.Error()) {
return exitStatus, ErrExecDisconnected
}

Expand Down

0 comments on commit 5f337b4

Please sign in to comment.