Skip to content

Improve console disconnections #1501

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

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions cmd/incus/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ func (c *cmdConsole) text(d incus.InstanceServer, name string) error {
}

close(consoleDisconnect)

// Make sure we leave the user back to a clean prompt.
fmt.Printf("\r\n")
}()

// Attach to the instance console
Expand Down
10 changes: 3 additions & 7 deletions cmd/incusd/instance_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -322,22 +323,17 @@ func (s *consoleWs) doConsole(op *operations.Operation) error {
s.connsLock.Unlock()

defer func() {
_ = consoleConn.WriteMessage(websocket.BinaryMessage, []byte("\n\r"))
_ = consoleConn.Close()
_ = ctrlConn.Close()
}()

// Write a reset escape sequence to the console to cancel any ongoing reads to the handle
// and then close it. This ordering is important, close the console before closing the
// websocket to ensure console doesn't get stuck reading.
_, err = console.Write([]byte("\x1bc"))
if err != nil {
_ = console.Close()
return err
}
_, _ = console.Write([]byte("\x1bc"))

err = console.Close()
if err != nil {
if err != nil && !errors.Is(err, os.ErrClosed) {
return err
}

Expand Down
Loading