Prevent crashes on shutdown due to lock being held

Former-commit-id: 6a74f524e558100dfb3e54779020cd3407706e08
This commit is contained in:
John Sully 2020-10-27 04:53:19 +00:00
parent cba89cf9f9
commit b226b318ff
2 changed files with 8 additions and 7 deletions

View File

@ -2221,10 +2221,11 @@ void processClients();
* The most important is freeClientsInAsyncFreeQueue but we also
* call some other low-risk functions. */
void beforeSleep(struct aeEventLoop *eventLoop) {
AeLocker locker;
UNUSED(eventLoop);
int iel = ielFromEventLoop(eventLoop);
aeAcquireLock();
locker.arm();
processClients();
/* Handle precise timeouts of blocked clients. */
@ -2232,9 +2233,9 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
/* Handle TLS pending data. (must be done before flushAppendOnlyFile) */
if (tlsHasPendingData()) {
aeReleaseLock();
locker.release();
tlsProcessPendingData();
aeAcquireLock();
locker.arm();
}
/* If tls still has pending unread data don't sleep at all. */
@ -2299,9 +2300,9 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
first so perform it here */
bool fSentReplies = false;
if (listLength(g_pserver->clients_to_close)) {
aeReleaseLock();
locker.disarm();
handleClientsWithPendingWrites(iel, aof_state);
aeAcquireLock();
locker.arm();
fSentReplies = true;
}
@ -2311,7 +2312,7 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
/* Before we are going to sleep, let the threads access the dataset by
* releasing the GIL. Redis main thread will not touch anything at this
* time. */
aeReleaseLock();
locker.disarm();
if (!fSentReplies)
handleClientsWithPendingWrites(iel, aof_state);
if (moduleCount()) moduleReleaseGIL(TRUE /*fServerThread*/);

View File

@ -215,7 +215,7 @@ proc test_slave_buffers {test_name cmd_count payload_len limit_memory pipeline}
set used_no_repl [expr {$new_used - $mem_not_counted_for_evict}]
set delta [expr {($used_no_repl - $client_buf) - ($orig_used_no_repl - $orig_client_buf)}]
assert {[$master dbsize] == 100}
assert_equal [$master dbsize] 100
assert {$slave_buf > 2*1024*1024} ;# some of the data may have been pushed to the OS buffers
set delta_max [expr {$cmd_count / 2}] ;# 1 byte unaccounted for, with 1M commands will consume some 1MB
assert {$delta < $delta_max && $delta > -$delta_max}