Skip to content

Commit

Permalink
clisqlshell: fix the behavior of ctrl+c under --no-line-editor
Browse files Browse the repository at this point in the history
Prior to this commit, there was a race condition in the cancellation
goroutine, between re-sending the signal and control flowing
out of the conditional into a call to a (nil) cancelFn.

This commit fixes that.

(No release note because the feature has not been released yet.)

Release note: None
  • Loading branch information
knz committed Oct 26, 2022
1 parent 655bde2 commit 8cb34c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/cli/clisqlshell/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,7 @@ func (c *cliState) maybeHandleInterrupt() func() {
// by re-throwing the signal after stopping the signal capture.
signal.Reset(os.Interrupt)
_ = sysutil.InterruptSelf()
return
}

fmt.Fprintf(c.iCtx.stderr, "\nattempting to cancel query...\n")
Expand Down
27 changes: 24 additions & 3 deletions pkg/cli/interactive_tests/test_interrupt.tcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#! /usr/bin/env expect -f

# Disabled until https://github.com/cockroachdb/cockroach/issues/76483 is resolved.

source [file join [file dirname $argv0] common.tcl]

start_server $argv
Expand Down Expand Up @@ -47,9 +45,32 @@ send "\r"
eexpect "defaultdb>"
end_test

# Quit the SQL client, and open a unix shell.
# Quit the SQL client.
send_eof
eexpect eof

start_test "Check that interrupt without a line editor quits the shell."
# regression test for #90653.
spawn $argv sql --no-line-editor
eexpect "defaultdb>"
interrupt
set timeout 1
expect {
"attempting to cancel query" { exit 1 }
"panic: runtime error" { exit 1 }
timeout {}
}
set timeout 30
interrupt
expect {
"attempting to cancel query" { exit 1 }
"panic: runtime error" { exit 1 }
eof {}
}
end_test


# Open a unix shell.
spawn /bin/bash
set shell2_spawn_id $spawn_id
send "PS1=':''/# '\r"
Expand Down

0 comments on commit 8cb34c6

Please sign in to comment.