diff --git a/CHANGELOG.md b/CHANGELOG.md index 169ea1597..079ff2282 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cli/connect/console.go b/cli/connect/console.go index b84f1701e..9f42c3ac5 100644 --- a/cli/connect/console.go +++ b/cli/connect/console.go @@ -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 } @@ -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 { @@ -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)