diff options
author | Binbin <binloveplay1314@qq.com> | 2022-11-05 00:46:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-04 18:46:37 +0200 |
commit | fac188b49d9680fdeb90332f163e5634cec1ea13 (patch) | |
tree | f39837f530ebc0ed32e7edc2cae2020807900431 /tests/unit | |
parent | c337c0a8a49d7cb64617b0a414d05b31425666f7 (diff) | |
download | redis-fac188b49d9680fdeb90332f163e5634cec1ea13.tar.gz |
Introduce socket shutdown into connection type, used if a fork is active (#11376)
Introduce socket `shutdown()` into connection type, and use it
on normal socket if a fork is active. This allows us to close
client connections when there are child processes sharing the
file descriptors.
Fixes #10077. The reason is that since the `fork()` child is holding
the file descriptors, the `close` in `unlinkClient -> connClose`
isn't sufficient. The client will not realize that the connection is
disconnected until the child process ends.
Let's try to be conservative and only use shutdown when the fork is active.
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/introspection.tcl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/unit/introspection.tcl b/tests/unit/introspection.tcl index 73f1649a7..25e46d6ab 100644 --- a/tests/unit/introspection.tcl +++ b/tests/unit/introspection.tcl @@ -54,6 +54,44 @@ start_server {tags {"introspection"}} { # After killing `me`, the first ping will throw an error assert_error "*I/O error*" {r ping} assert_equal "PONG" [r ping] + + $rd1 close + $rd2 close + $rd3 close + $rd4 close + } + + test "CLIENT KILL close the client connection during bgsave" { + # Start a slow bgsave, trigger an active fork. + r flushall + r set k v + r config set rdb-key-save-delay 10000000 + r bgsave + wait_for_condition 1000 10 { + [s rdb_bgsave_in_progress] eq 1 + } else { + fail "bgsave did not start in time" + } + + # Kill (close) the connection + r client kill skipme no + + # In the past, client connections needed to wait for bgsave + # to end before actually closing, now they are closed immediately. + assert_error "*I/O error*" {r ping} ;# get the error very quickly + assert_equal "PONG" [r ping] + + # Make sure the bgsave is still in progress + assert_equal [s rdb_bgsave_in_progress] 1 + + # Stop the child before we proceed to the next test + r config set rdb-key-save-delay 0 + r flushall + wait_for_condition 1000 10 { + [s rdb_bgsave_in_progress] eq 0 + } else { + fail "bgsave did not stop in time" + } } test {MONITOR can log executed commands} { |