Mailing List Archive

Ticket #11410: backend hang: mpeg recordings with vbi sometimes hang at finish
#11410: backend hang: mpeg recordings with vbi sometimes hang at finish
--------------------------------------------+------------------------------
Reporter: rd.mora@… | Owner: danielk
Type: Bug Report - Hang/Deadlock | Status: new
Priority: major | Milestone: unknown
Component: MythTV - Recording | Version: 0.26-fixes
Severity: high | Keywords: mpegrecorder vbi
Ticket locked: 0 | hang
--------------------------------------------+------------------------------
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)

--
Ticket URL: <http://code.mythtv.org/trac/ticket/11410>
MythTV <http://code.mythtv.org/trac>
MythTV Media Center
_______________________________________________
mythtv-commits mailing list
mythtv-commits@mythtv.org
http://www.mythtv.org/mailman/listinfo/mythtv-commits
Re: Ticket #11410: backend hang: mpeg recordings with vbi sometimes hang at finish [ In reply to ]
#11410: backend hang: mpeg recordings with vbi sometimes hang at finish
----------------------------------------+----------------------------
Reporter: rd.mora@… | Owner: danielk
Type: Bug Report - Hang/Deadlock | Status: new
Priority: major | Milestone: unknown
Component: MythTV - Recording | Version: 0.26-fixes
Severity: high | Resolution:
Keywords: mpegrecorder vbi hang | Ticket locked: 0
----------------------------------------+----------------------------

Comment (by rd.mora@…):

My apologies, let me try that again....

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)
}}}

--
Ticket URL: <http://code.mythtv.org/trac/ticket/11410#comment:1>
MythTV <http://code.mythtv.org/trac>
MythTV Media Center
_______________________________________________
mythtv-commits mailing list
mythtv-commits@mythtv.org
http://www.mythtv.org/mailman/listinfo/mythtv-commits
Re: Ticket #11410: backend hang: mpeg recordings with vbi sometimes hang at finish [ In reply to ]
#11410: backend hang: mpeg recordings with vbi sometimes hang at finish
----------------------------------------+----------------------------
Reporter: rd.mora@… | Owner: danielk
Type: Bug Report - Hang/Deadlock | Status: new
Priority: minor | Milestone: unknown
Component: MythTV - Recording | Version: 0.26-fixes
Severity: medium | Resolution:
Keywords: mpegrecorder vbi hang | Ticket locked: 0
----------------------------------------+----------------------------
Changes (by wagnerrp):

* priority: major => minor
* severity: high => medium


Old description:

> 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)

New description:

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)
}}}

--

--
Ticket URL: <http://code.mythtv.org/trac/ticket/11410#comment:1>
MythTV <http://code.mythtv.org/trac>
MythTV Media Center
_______________________________________________
mythtv-commits mailing list
mythtv-commits@mythtv.org
http://www.mythtv.org/mailman/listinfo/mythtv-commits
Re: Ticket #11410: backend hang: mpeg recordings with vbi sometimes hang at finish [ In reply to ]
#11410: backend hang: mpeg recordings with vbi sometimes hang at finish
----------------------------------------+----------------------------
Reporter: rd.mora@… | Owner: danielk
Type: Bug Report - Hang/Deadlock | Status: new
Priority: minor | Milestone: unknown
Component: MythTV - Recording | Version: 0.26-fixes
Severity: medium | Resolution:
Keywords: mpegrecorder vbi hang | Ticket locked: 0
----------------------------------------+----------------------------

Comment (by rd.mora@…):

Hmm, that diff isn't going to work - it is still possible for the vbi
thread to be blocked in a read before we signal it and then stop the
encoding. Even moving the StopEncoding() to after the vbi_thread->wait()
won't work - the vbi_thread could be blocked on a read and because there
is now nothing reading data from the mpeg FD the driver buffers full up
and it stops writing to the VBI FD. The best solution seems to be to put
the VBI FD into non-blocking mode, for which the changes required actually
seem pretty minimal, i.e.:

{{{
diff --git a/mythtv/libs/libmythtv/v4lrecorder.cpp
b/mythtv/libs/libmythtv/v4lrecorder.cpp
index a16214f..79239ad 100644
--- a/mythtv/libs/libmythtv/v4lrecorder.cpp
+++ b/mythtv/libs/libmythtv/v4lrecorder.cpp
@@ -129,7 +129,7 @@ int V4LRecorder::OpenVBIDevice(void)
}
else if (VBIMode::NTSC_CC == vbimode)
{
- fd = open(vbidev.constData(), O_RDONLY/*|O_NONBLOCK*/);
+ fd = open(vbidev.constData(), O_RDONLY|O_NONBLOCK);
}
else
{
@@ -326,7 +326,7 @@ void V4LRecorder::RunVBIDevice(void)
}
ptr = buf;
}
- else if (ret < 0)
+ else if ((ret < 0) && (EAGAIN != errno) && (EINTR != errno))
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Reading VBI data" + ENO);
}
}}}

NOTE: This diff does not handle PAL VBI, just NTSC!

I'll update the ticket if I run into any trouble with this change....

--
Ticket URL: <http://code.mythtv.org/trac/ticket/11410#comment:2>
MythTV <http://code.mythtv.org/trac>
MythTV Media Center
_______________________________________________
mythtv-commits mailing list
mythtv-commits@mythtv.org
http://www.mythtv.org/mailman/listinfo/mythtv-commits
Re: Ticket #11410: backend hang: mpeg recordings with vbi sometimes hang at finish [ In reply to ]
#11410: backend hang: mpeg recordings with vbi sometimes hang at finish
----------------------------------------+----------------------------
Reporter: rd.mora@… | Owner: danielk
Type: Bug Report - Hang/Deadlock | Status: closed
Priority: minor | Milestone: unknown
Component: MythTV - Recording | Version: 0.26-fixes
Severity: medium | Resolution: Abandoned
Keywords: mpegrecorder vbi hang | Ticket locked: 0
----------------------------------------+----------------------------
Changes (by Stuart Auchterlonie):

* status: new => closed
* resolution: => Abandoned


Comment:

Closing out old tickets. Does anyone actually still use a device that
needs this?

--
Ticket URL: <https://code.mythtv.org/trac/ticket/11410#comment:3>
MythTV <http://www.mythtv.org>
MythTV Media Center