Opened 11 years ago
Last modified 4 years ago
#11410 closed Bug Report - Hang/Deadlock
backend hang: mpeg recordings with vbi sometimes hang at finish — at Version 1
Reported by: | Owned by: | danielk | |
---|---|---|---|
Priority: | minor | Milestone: | unknown |
Component: | MythTV - Recording | Version: | 0.26-fixes |
Severity: | medium | Keywords: | mpegrecorder vbi hang |
Cc: | Ticket locked: | no |
Description (last modified by )
Witnessed mpeg recordings with vbi occasionally hanging at finish (causing the backend in general to hang) and under gdb saw:
Thread 3 (Thread 0x7fbd69ffb700 (LWP 8322)): #0 0x00007fbd8bf7a61c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 #1 0x00007fbd8c207699 in QWaitCondition::wait(QMutex*, unsigned long) () from /usr/lib64/libQtCore.so.4 #2 0x00007fbd8c206824 in QThread::wait(unsigned long) () from /usr/lib64/libQtCore.so.4 #3 0x00007fbd9293f9bc in MpegRecorder::run (this=0x7fbd6c224d00) at mpegrecorder.cpp:1124 #4 0x00007fbd91b9ec07 in MThread::run (this=0x7fbd6c9f35a0) at mthread.cpp:319 #5 0x00007fbd8c206775 in ?? () from /usr/lib64/libQtCore.so.4 #6 0x00007fbd8bf767b6 in start_thread () from /lib64/libpthread.so.0 #7 0x00007fbd8b5399cd in clone () from /lib64/libc.so.6 #8 0x0000000000000000 in ?? () Thread 2 (Thread 0x7fbd697fa700 (LWP 8323)): #0 0x00007fbd8bf7d76d in read () from /lib64/libpthread.so.0 #1 0x00007fbd9292263c in V4LRecorder::RunVBIDevice (this=0x7fbd6c224d00) at v4lrecorder.cpp:308 #2 0x00007fbd9291aeb2 in VBIThread::run (this=0x1111d40) at v4lrecorder.h:82 #3 0x00007fbd8c206775 in ?? () from /usr/lib64/libQtCore.so.4 #4 0x00007fbd8bf767b6 in start_thread () from /lib64/libpthread.so.0 #5 0x00007fbd8b5399cd in clone () from /lib64/libc.so.6 #6 0x0000000000000000 in ?? ()
Looking at mpegrecorder.cpp:
1113 LOG(VB_RECORD, LOG_INFO, LOC + "run finishing up"); 1114 1115 StopEncoding(); 1116 1117 { 1118 QMutexLocker locker(&pauseLock); 1119 request_helper = false; 1120 } 1121 1122 if (vbi_thread) 1123 { 1124 vbi_thread->wait(); 1125 delete vbi_thread; 1126 vbi_thread = NULL; 1127 CloseVBIDevice(); 1128 } 1129 1130 FinishRecording();
Line 1119 signals the vbi thread to stop reading and exit, however, the encoder is signaled to stop *before* this on line 1115. Thus it is possible for the vbi thread to return from select, try to read data from the vbi fd and then block on the read because the vbi fd is no longer returning data (has been stopped).
Simple solution seems to be to swap the order, i.e. signal vbi thread to stop reading before stopping the encoder. I have no idea if there are any unforeseen consequences to this though..... comments?
diff --git a/mythtv/libs/libmythtv/mpegrecorder.cpp b/mythtv/libs/libmythtv/mpegrecorder.cpp index b158513..35644af 100644 --- a/mythtv/libs/libmythtv/mpegrecorder.cpp +++ b/mythtv/libs/libmythtv/mpegrecorder.cpp @@ -1112,13 +1112,13 @@ void MpegRecorder::run(void) LOG(VB_RECORD, LOG_INFO, LOC + "run finishing up"); - StopEncoding(); - { QMutexLocker locker(&pauseLock); request_helper = false; } + StopEncoding(); + if (vbi_thread) { vbi_thread->wait(); lines 1-20/20 (END)