Fix crash in script timeout during AOF loading (#7870)

This commit is contained in:
Oran Agra 2020-10-01 11:27:45 +03:00 committed by GitHub
parent b8187d39fb
commit dc803d25a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 4 deletions

View File

@ -1547,17 +1547,21 @@ void resetClient(client *c) {
* path, it is not really released, but only marked for later release. */ * path, it is not really released, but only marked for later release. */
void protectClient(client *c) { void protectClient(client *c) {
c->flags |= CLIENT_PROTECTED; c->flags |= CLIENT_PROTECTED;
if (c->conn) {
connSetReadHandler(c->conn,NULL); connSetReadHandler(c->conn,NULL);
connSetWriteHandler(c->conn,NULL); connSetWriteHandler(c->conn,NULL);
}
} }
/* This will undo the client protection done by protectClient() */ /* This will undo the client protection done by protectClient() */
void unprotectClient(client *c) { void unprotectClient(client *c) {
if (c->flags & CLIENT_PROTECTED) { if (c->flags & CLIENT_PROTECTED) {
c->flags &= ~CLIENT_PROTECTED; c->flags &= ~CLIENT_PROTECTED;
if (c->conn) {
connSetReadHandler(c->conn,readQueryFromClient); connSetReadHandler(c->conn,readQueryFromClient);
if (clientHasPendingReplies(c)) clientInstallWriteHandler(c); if (clientHasPendingReplies(c)) clientInstallWriteHandler(c);
} }
}
} }
/* Like processMultibulkBuffer(), but for the inline protocol instead of RESP, /* Like processMultibulkBuffer(), but for the inline protocol instead of RESP,

View File

@ -430,6 +430,45 @@ start_server {tags {"scripting"}} {
set res set res
} {102} } {102}
test {EVAL timeout from AOF} {
# generate a long running script that is propagated to the AOF as script
# make sure that the script times out during loading
r config set appendonly no
r config set aof-use-rdb-preamble no
r config set lua-replicate-commands no
r flushall
r config set appendonly yes
wait_for_condition 50 100 {
[s aof_rewrite_in_progress] == 0
} else {
fail "AOF rewrite can't complete after CONFIG SET appendonly yes."
}
r config set lua-time-limit 1
set rd [redis_deferring_client]
set start [clock clicks -milliseconds]
$rd eval {redis.call('set',KEYS[1],'y'); for i=1,1500000 do redis.call('ping') end return 'ok'} 1 x
$rd flush
after 100
catch {r ping} err
assert_match {BUSY*} $err
$rd read
set elapsed [expr [clock clicks -milliseconds]-$start]
if {$::verbose} { puts "script took $elapsed milliseconds" }
set start [clock clicks -milliseconds]
$rd debug loadaof
$rd flush
after 100
catch {r ping} err
assert_match {LOADING*} $err
$rd read
set elapsed [expr [clock clicks -milliseconds]-$start]
if {$::verbose} { puts "loading took $elapsed milliseconds" }
$rd close
r get x
} {y}
r config set aof-use-rdb-preamble yes
r config set lua-replicate-commands yes
test {We can call scripts rewriting client->argv from Lua} { test {We can call scripts rewriting client->argv from Lua} {
r del myset r del myset
r sadd myset a b c r sadd myset a b c