Skip to content
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

lxc: Handle sigkill in vga() properly to clean spice sockets and avoid accumulating them #14350

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lxc/console.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package main

import (
"context"
"errors"
"fmt"
"io"
"net"
"os"
"os/exec"
"os/signal"
"runtime"
"strconv"
"sync"
"syscall"

"github.com/gorilla/websocket"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -237,6 +240,12 @@ func (c *cmdConsole) vga(d lxd.InstanceServer, name string) error {
var err error
conf := c.global.conf

// Create a context that is canceled on signal reception.
// This is used to enable the function to execute any cleanup defer statements
// before exiting.
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
tomponline marked this conversation as resolved.
Show resolved Hide resolved
defer stop()

// We currently use the control websocket just to abort in case of errors.
controlDone := make(chan struct{}, 1)
handler := func(control *websocket.Conn) {
Expand Down Expand Up @@ -284,7 +293,8 @@ func (c *cmdConsole) vga(d lxd.InstanceServer, name string) error {
}

// Listen on the socket.
listener, err = net.Listen("unix", path.Name())
lc := net.ListenConfig{}
listener, err = lc.Listen(ctx, "unix", path.Name())
if err != nil {
return err
}
Expand Down
Loading