awslabs / amazon-kinesis-video-streams-pic

Apache License 2.0
50 stars 47 forks source link

[BUG] TimerQueue executorLock may cause deadlock #163

Closed vincentyanzhao closed 2 years ago

vincentyanzhao commented 2 years ago

Describe the bug

After the thread functiontimer QueueExecutor starts calling the lock for the first time, it enters a long wait; Other threads calling the API will deadlock; I encountered this situation in my own program;But there are no problems in the demo. It's strange !!!!

SDK version number the SDK version commit d10936c70ef00941226f431b9bda46eca5aa2f0a

Expected behavior I think that once the thread function QueueExecutor is locked by pTimerQueue->executorLock , other threads call API ,it will deadlock by pTimerQueue->executorLock; Example timerQueueCancelTimer

Screenshots PVOID timerQueueExecutor(PVOID args) { .... MUTEX_LOCK(pTimerQueue->executorLock); locked = TRUE; // The main loop while (!ATOMIC_LOAD_BOOL(&pTimerQueue->shutdown)) { // Block/wait until signaled or timed out curTime = GETTIME(); if (curTime < pTimerQueue->invokeTime) { CVAR_WAIT(pTimerQueue->executorCvar, pTimerQueue->executorLock, pTimerQueue->invokeTime - curTime); } .... }

MUTEX_UNLOCK(pTimerQueue->executorLock);
locked = FALSE;

.... }

Desktop (please complete the following information):

MushMal commented 2 years ago

While the main waiting is done in the CVAR the lock is unlocked and the CVAR is awaiting for the signaling state

https://github.com/awslabs/amazon-kinesis-video-streams-pic/blob/master/src/utils/src/TimerQueue.c#L546

The woken executor thread will check for a few conditions (like spurious wake ups) and will handle the task. NOTE: the tasks have to be "prompt"