-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli,sdnotify: improve the handling of unix socket directories
tldr: This patch makes it easier for users to understand when CockroachDB has a problem using/creating unix sockets, and what they can do to avert the situation. Example, before; ``` $ cockroach start-single-node --insecure --background ... listen unixgram /data/home/kena/cockroach/this-is-a-very-long-directory-name-the-point-is-to-be-more-than-one-hundred-and-twenty-three-characters/sdnotify2139543236/notify.sock: bind: invalid argument ``` Example, after: ``` $ cockroach start-single-node --insecure --background ERROR: no suitable directory found for the --background notify socket HINT: Avoid using --background altogether (preferred), or use a shorter directory name for --socket-dir, TMPDIR or the current directory. ``` **Context:** CockroachDB uses unix sockets both to handle `--background` and to create a postgres-compatible SQL client socket via `--socket-dir`. For `--background`, the logic was previously hardwired to always use `os.TempDir()`, i.e. either `$TMPDIR` or `/tmp`. On Unix, socket objects are commonly limited to 128 bytes; that's e.g. 104 path characters including final NUL on BSD, 108 on glibc. When the actual length is larger, creating the socket fails with a confusing error `bind: invalid argument`. **The problem:** Users have reported issues in the following circumstances: - when setting their CWD/$TMPDIR to a long directory name, they expected `--socket-dir` to also influence the socket name used for `--background`. Instead, `--background` failed with a hard-to-understand error. - when running tests inside a container/sandbox with a long prefix, they were confused that `--background` / `--socket-dir=.` did not work properly. - they use macOS which has very large directory names in $TMPDIR. To improve user experience, this patch changes the behavior as described in the release notes below below. Release note (cli change): CockroachDB now produces a clearer error when the path specified via `--socket-dir` is too long. Release note (cli change): When the flag `--background` is specified, CockroachDB now makes 3 attempts to find a suitable directory to create the notification socket: the value of `--socket-dir` if specified, the value of `$TMPDIR` (or /tmp if the env var is empty), and the current working directory. If none of these directories has a name short enough, an explanatory error is printed.
- Loading branch information
Showing
7 changed files
with
149 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#! /usr/bin/env expect -f | ||
# | ||
source [file join [file dirname $argv0] common.tcl] | ||
|
||
set longname "this-is-a-very-long-directory-name-the-point-is-to-be-more-than-one-hundred-and-twenty-three-characters/and-we-also-need-to-break-it-into-two-parts" | ||
|
||
spawn /bin/bash | ||
send "PS1=':''/# '\r" | ||
eexpect ":/# " | ||
|
||
send "mkdir -p $longname\r" | ||
eexpect ":/# " | ||
|
||
start_test "Check that the socket-dir flag checks the length of the directory." | ||
send "$argv start-single-node --insecure --socket-dir=$longname\r" | ||
eexpect "value of --socket-dir is too long" | ||
eexpect "socket directory name must be shorter" | ||
eexpect ":/# " | ||
end_test | ||
|
||
set crdb [file normalize $argv] | ||
send "export BASEDIR=\$PWD\r" | ||
eexpect ":/# " | ||
send "export PREVTMP=\$TMPDIR\r" | ||
eexpect ":/# " | ||
|
||
start_test "Check that --background complains about the directory name if there is no default." | ||
send "cd $longname\r" | ||
eexpect ":/# " | ||
send "export TMPDIR=\$PWD\r" | ||
eexpect ":/# " | ||
send "$crdb start-single-node --insecure --background\r" | ||
eexpect "no suitable directory found for the --background notify socket" | ||
eexpect "use a shorter directory name" | ||
eexpect ":/# " | ||
end_test | ||
|
||
start_test "Check that --background can use --socket-name if specified and set to sane default." | ||
send "$crdb start-single-node --insecure --background --socket-dir=\$BASEDIR --pid-file=\$BASEDIR/server_pid\r" | ||
eexpect ":/# " | ||
# check the server is running. | ||
system "$crdb sql --insecure -e 'select 1'" | ||
stop_server $crdb | ||
end_test | ||
|
||
start_test "Check that --background can use TMPDIR if specified and set to sane default." | ||
# NB: we use a single-command override of TMPDIR (as opposed to using 'export') so that | ||
# the following test below can reuse the value set above. | ||
send "TMPDIR=\$PREVTMP $crdb start-single-node --insecure --background --pid-file=\$BASEDIR/server_pid\r" | ||
eexpect ":/# " | ||
# check the server is running. | ||
system "$crdb sql --insecure -e 'select 1'" | ||
stop_server $crdb | ||
end_test | ||
|
||
start_test "Check that --background can use cwd if TMPDIR is invalid." | ||
# NB: at this point TMPDIR is still long, as per previous test. | ||
send "cd \$BASEDIR\r" | ||
eexpect ":/# " | ||
send "$crdb start-single-node --insecure --background --pid-file=server_pid\r" | ||
eexpect ":/# " | ||
# check the server is running. | ||
system "$crdb sql --insecure -e 'select 1'" | ||
stop_server $crdb | ||
end_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters