-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-5479: Prevent mysqld from stealing Unix socket of another active instance #4874
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
Open
FaramosCZ
wants to merge
1
commit into
MariaDB:main
Choose a base branch
from
FaramosCZ:MDEV-5479
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+192
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,19 @@ | ||
| # | ||
| # MDEV-5479: Prevent mysqld from unlinking a Unix socket | ||
| # file actively used by another process | ||
| # | ||
| # | ||
| # Test 1: Server must refuse to start when a listener is | ||
| # already present on the socket path | ||
| # | ||
| FOUND 1 /\[ERROR\] Another process is already listening on the socket file/ in socket_conflict.err | ||
| # | ||
| # Test 2: Stale socket file must be cleaned up at startup | ||
| # | ||
| # restart | ||
| SELECT 1; | ||
| 1 | ||
| 1 | ||
| # | ||
| # End of 13.0 tests | ||
| # |
This file contains hidden or 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,118 @@ | ||
| --source include/not_windows.inc | ||
| --source include/not_embedded.inc | ||
|
|
||
| --echo # | ||
| --echo # MDEV-5479: Prevent mysqld from unlinking a Unix socket | ||
| --echo # file actively used by another process | ||
| --echo # | ||
|
|
||
| # Shut down the server once; both tests run while it is down. | ||
| --source include/shutdown_mysqld.inc | ||
|
|
||
| --echo # | ||
| --echo # Test 1: Server must refuse to start when a listener is | ||
| --echo # already present on the socket path | ||
| --echo # | ||
|
|
||
| # Create a fake listener on the default socket path. | ||
| # The child process creates and holds the listening socket; | ||
| # the parent must not touch the socket object at all, because | ||
| # Perl's IO::Socket->close() calls shutdown(SHUT_RDWR) which | ||
| # would kill the listener in the child too. | ||
| perl; | ||
| use IO::Socket::UNIX; | ||
| my $path= $ENV{MASTER_MYSOCK}; | ||
| unlink $path if -e $path; | ||
| my $pid= fork(); | ||
| die "fork: $!" unless defined $pid; | ||
| if ($pid == 0) | ||
| { | ||
| # Detach from parent's process group and close inherited | ||
| # pipe fds. mysqltest uses popen() for perl blocks and | ||
| # reads stdout to completion -- the child must close its | ||
| # copy of the pipe so mysqltest can proceed. | ||
| setpgrp(0, 0); | ||
| open(STDIN, '<', '/dev/null'); | ||
| open(STDOUT, '>', '/dev/null'); | ||
| open(STDERR, '>', '/dev/null'); | ||
| my $srv= IO::Socket::UNIX->new( | ||
| Type => SOCK_STREAM, | ||
| Local => $path, | ||
| Listen => 1, | ||
| ) or exit 1; | ||
| while (1) { sleep 60; } | ||
| } | ||
| # Parent: wait for child to create the socket (up to 60s) | ||
| for (1..600) | ||
| { | ||
| last if -S $path; | ||
| select(undef, undef, undef, 0.1); | ||
| } | ||
| die "Fake listener not created at $path\n" unless -S $path; | ||
| my $pidfile= "$ENV{MYSQLTEST_VARDIR}/tmp/fake_server.pid"; | ||
| open(my $fh, '>', $pidfile) or die "Cannot write $pidfile: $!\n"; | ||
| print $fh $pid; | ||
| close $fh; | ||
| EOF | ||
|
|
||
| --let errorlog=$MYSQL_TMP_DIR/socket_conflict.err | ||
| --let SEARCH_FILE=$errorlog | ||
|
|
||
| # Use --loose-skip-innodb to skip InnoDB initialization, which | ||
| # runs before network_init() and would otherwise be slow on CI. | ||
| --error 1 | ||
| --exec $MYSQLD --defaults-group-suffix=.1 --defaults-file=$MYSQLTEST_VARDIR/my.cnf --loose-skip-innodb --log-error=$errorlog | ||
|
|
||
| --let SEARCH_PATTERN=\[ERROR\] Another process is already listening on the socket file | ||
| --source include/search_pattern_in_file.inc | ||
|
|
||
| --remove_file $SEARCH_FILE | ||
|
|
||
| # Kill the fake listener and clean up its socket file | ||
| perl; | ||
| my $pidfile= "$ENV{MYSQLTEST_VARDIR}/tmp/fake_server.pid"; | ||
| open(my $fh, '<', $pidfile) or die "Cannot read $pidfile: $!\n"; | ||
| my $pid= <$fh>; | ||
| chomp $pid; | ||
| close $fh; | ||
| kill 'TERM', $pid; | ||
| # The child runs in its own process group (setpgrp) and was | ||
| # reparented to init, so waitpid won't work here. Poll until | ||
| # the process is gone. | ||
| for (1..600) | ||
| { | ||
| last unless kill(0, $pid); | ||
| select(undef, undef, undef, 0.1); | ||
| } | ||
| unlink $pidfile; | ||
| unlink $ENV{MASTER_MYSOCK}; | ||
| EOF | ||
|
|
||
| --echo # | ||
| --echo # Test 2: Stale socket file must be cleaned up at startup | ||
| --echo # | ||
|
|
||
| # Create a stale Unix socket at the default socket path. | ||
| # The socket is bound then immediately closed, leaving an | ||
| # orphaned file with no listener behind it. | ||
| perl; | ||
| use IO::Socket::UNIX; | ||
| my $path= $ENV{MASTER_MYSOCK}; | ||
| my $srv= IO::Socket::UNIX->new( | ||
| Type => SOCK_STREAM, | ||
| Local => $path, | ||
| Listen => 1, | ||
| ) or die "Cannot create socket at $path: $!\n"; | ||
| $srv->close(); | ||
| EOF | ||
|
|
||
| # Start the server normally -- it should detect the stale | ||
| # socket, remove it, and bind successfully. | ||
| --source include/start_mysqld.inc | ||
|
|
||
| # Verify the server is operational | ||
| SELECT 1; | ||
|
|
||
| --echo # | ||
| --echo # End of 13.0 tests | ||
| --echo # | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.