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 socket is closed and the
error we get is a `connection reset by peer` or a `Unexpected EOF` instead
of a EOF.
So this helps handle these errors similarly to make the command exit
cleanly in these scenarios.
Since both errors are of type errorString, the only way to check it
is to see if they contains the expected substring.

Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
  • Loading branch information
hamistao committed Sep 6, 2024
1 parent 8665ae0 commit 0f5be4b
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) {
// The error can be different depending on why the VM disconnected
// so we handle these cases similarly.
if errors.Is(err, io.EOF) || strings.Contains(err.Error(), io.ErrUnexpectedEOF.Error()) || strings.Contains(err.Error(), syscall.ECONNRESET.Error()) {
return exitStatus, ErrExecDisconnected
}

Expand Down

0 comments on commit 0f5be4b

Please sign in to comment.