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

connect: fix terminal after executing os.exit() #440

Merged
merged 1 commit into from
May 2, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- ``--dynamic`` option for `tt install tarantool` command to build non-static tarantool executable.

### Fixed

- ``tt connect`` command does not break a console after executing `os.exit()` command anymore.

## [1.0.2] - 2023-04-21

### Fixed
Expand Down
15 changes: 9 additions & 6 deletions cli/connect/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ func (console *Console) Run() error {

console.prompt.Run()

// Sets the terminal modes to “sane” values to workaround
// bug https://github.com/c-bata/go-prompt/issues/228
sttySane := exec.Command("stty", "sane")
sttySane.Stdin = os.Stdin
_ = sttySane.Run()

return nil
}

Expand All @@ -166,6 +160,12 @@ func (console *Console) Close() {
if console.conn != nil {
console.conn.Close()
}

// Sets the terminal modes to “sane” values to workaround
// bug https://github.com/c-bata/go-prompt/issues/228
sttySane := exec.Command("stty", "sane")
sttySane.Stdin = os.Stdin
_ = sttySane.Run()
}

func loadHistory(console *Console) error {
Expand Down Expand Up @@ -247,6 +247,9 @@ func getExecutor(console *Console) prompt.Executor {
var data string
if _, err := console.conn.Eval(consoleEvalFuncBody, args, opts); err != nil {
if err == io.EOF {
// We need to call 'console.Close()' here because in some cases (e.g 'os.exit()')
// it won't be called from 'defer console.Close' in 'connect.runConsole()'.
console.Close()
log.Fatalf("Connection was closed. Probably instance process isn't running anymore")
} else {
log.Fatalf("Failed to execute command: %s", err)
Expand Down