-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't initiate new connections during a client shutdown (async API) (#…
…225) * Don't accept new commands when the client is about to shutdown. * Don't follow redirects when a shutdown is requested. * No slot map updates during a client shutdown. Co-authored-by: Viktor Söderqvist <[email protected]>
- Loading branch information
1 parent
226a4c6
commit 1efe528
Showing
6 changed files
with
240 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
# | ||
# Verify that a client disconnects from known nodes without following | ||
# redirects, this to avoid reconnecting to already disconnected nodes. | ||
# The client will not accept new commands thereafter. | ||
# | ||
# Usage: $0 /path/to/clusterclient-binary | ||
|
||
clientprog=${1:-./clusterclient_async} | ||
testname=client-disconnect-test | ||
|
||
# Sync processes waiting for CONT signals. | ||
perl -we 'use sigtrap "handler", sub{exit}, "CONT"; sleep 1; die "timeout"' & | ||
syncpid1=$!; | ||
|
||
# Start simulated redis node #1 | ||
timeout 5s ./simulated-redis.pl -p 7401 -d --sigcont $syncpid1 <<'EOF' & | ||
EXPECT CONNECT | ||
EXPECT ["CLUSTER", "SLOTS"] | ||
SEND [[0, 16383, ["127.0.0.1", 7401, "nodeid1"]]] | ||
EXPECT CLOSE | ||
EXPECT CONNECT | ||
EXPECT ["SET", "foo", "initial"] | ||
SEND +OK | ||
EXPECT ["SET", "foo", "redirect"] | ||
SEND -MOVED 12182 127.0.0.1:7402 | ||
EXPECT CLOSE | ||
EOF | ||
server1=$! | ||
|
||
# Wait until node is ready to accept client connections | ||
wait $syncpid1; | ||
|
||
# Run client | ||
timeout 4s "$clientprog" --connection-events 127.0.0.1:7401 > "$testname.out" <<'EOF' | ||
SET foo initial | ||
# Send a command that is expected to be redirected just before | ||
# requesting a client disconnect. | ||
!async | ||
SET foo redirect | ||
!disconnect | ||
!sync | ||
# Commands are not accepted after a disconnect. | ||
SET foo not-accepted | ||
EOF | ||
clientexit=$? | ||
|
||
# Wait for server to exit | ||
wait $server1; server1exit=$? | ||
|
||
# Check exit statuses | ||
if [ $server1exit -ne 0 ]; then | ||
echo "Simulated server #1 exited with status $server1exit" | ||
exit $server1exit | ||
fi | ||
if [ $clientexit -ne 0 ]; then | ||
echo "$clientprog exited with status $clientexit" | ||
exit $clientexit | ||
fi | ||
|
||
expected="Event: connect to 127.0.0.1:7401 | ||
OK | ||
MOVED 12182 127.0.0.1:7402 | ||
Event: disconnect from 127.0.0.1:7401 | ||
error: client closing" | ||
|
||
echo "$expected" | diff -u - "$testname.out" || exit 99 | ||
|
||
# Clean up | ||
rm "$testname.out" |
104 changes: 104 additions & 0 deletions
104
tests/scripts/client-disconnect-without-slotmap-update-test.sh
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,104 @@ | ||
#!/bin/bash | ||
# | ||
# Verify that a client disconnects from known nodes without starting new | ||
# slot map updates. A client shouldn't reconnect or connect to new nodes | ||
# while shutting down. | ||
# | ||
# This testcase starts 2 cluster nodes and the client connects to both. | ||
# The client triggers a disconnect right after a command has been sent, | ||
# which will invoke its callback with a NULL reply. This NULL reply | ||
# should not trigger a slot map update which it would in other cases. | ||
# | ||
# Usage: $0 /path/to/clusterclient-binary | ||
|
||
clientprog=${1:-./clusterclient_async} | ||
testname=client-disconnect-test | ||
|
||
# Sync process just waiting for server to be ready to accept connection. | ||
perl -we 'use sigtrap "handler", sub{exit}, "CONT"; sleep 1; die "timeout"' & | ||
syncpid1=$! | ||
perl -we 'use sigtrap "handler", sub{exit}, "CONT"; sleep 1; die "timeout"' & | ||
syncpid2=$! | ||
|
||
# Start simulated redis node #1 | ||
timeout 5s ./simulated-redis.pl -p 7401 -d --sigcont $syncpid1 <<'EOF' & | ||
EXPECT CONNECT | ||
EXPECT ["CLUSTER", "SLOTS"] | ||
SEND [[0, 6000, ["127.0.0.1", 7401, "nodeid1"]],[6001, 16383, ["127.0.0.1", 7402, "nodeid2"]]] | ||
EXPECT CLOSE | ||
EXPECT CONNECT | ||
EXPECT ["SET", "bar", "initial"] | ||
SEND +OK | ||
# Normally a slot map update is expected here, but not during disconnects. | ||
EXPECT CLOSE | ||
EOF | ||
server1=$! | ||
|
||
# Start simulated redis node #2 | ||
timeout 5s ./simulated-redis.pl -p 7402 -d --sigcont $syncpid2 <<'EOF' & | ||
EXPECT CONNECT | ||
EXPECT ["SET", "foo", "initial"] | ||
SEND +OK | ||
EXPECT ["SET", "foo", "null-reply"] | ||
# The client will invoke callbacks for outstanding requests with a NULL reply. | ||
# Normally this would trigger a slot map update, but not during disconnects. | ||
EXPECT CLOSE | ||
EOF | ||
server2=$! | ||
|
||
# Wait until both nodes are ready to accept client connections | ||
wait $syncpid1 $syncpid2; | ||
|
||
# Run client | ||
timeout 4s "$clientprog" --connection-events 127.0.0.1:7401 > "$testname.out" <<'EOF' | ||
SET foo initial | ||
SET bar initial | ||
# Make sure a slot map update is not throttled. | ||
!sleep | ||
# Send a command just before requesting a client disconnect. | ||
# A NULL reply should not trigger a slot map update after a disconnect. | ||
!async | ||
SET foo null-reply | ||
!disconnect | ||
!sync | ||
EOF | ||
clientexit=$? | ||
|
||
# Wait for servers to exit | ||
wait $server1; server1exit=$? | ||
wait $server2; server2exit=$? | ||
|
||
# Check exit statuses | ||
if [ $server1exit -ne 0 ]; then | ||
echo "Simulated server #1 exited with status $server1exit" | ||
exit $server1exit | ||
fi | ||
if [ $server2exit -ne 0 ]; then | ||
echo "Simulated server #2 exited with status $server2exit" | ||
exit $server2exit | ||
fi | ||
if [ $clientexit -ne 0 ]; then | ||
echo "$clientprog exited with status $clientexit" | ||
exit $clientexit | ||
fi | ||
|
||
expected="Event: connect to 127.0.0.1:7402 | ||
OK | ||
Event: connect to 127.0.0.1:7401 | ||
OK | ||
Event: disconnect from 127.0.0.1:7401 | ||
error: Timeout | ||
Event: failed to disconnect from 127.0.0.1:7402" | ||
|
||
echo "$expected" | diff -u - "$testname.out" || exit 99 | ||
|
||
# Clean up | ||
rm "$testname.out" |