Opened 16 years ago

Closed 16 years ago

#5591 closed patch (fixed)

Fix ThreadedFileWriter potential deadlock

Reported by: jppoet@… Owned by: Isaac Richards
Priority: major Milestone: unknown
Component: mythtv Version: unknown
Severity: medium Keywords: ThreadedFileWriter deadlock
Cc: Ticket locked: no

Description

If ThreadedFileWriter::Write() is fed more data than can fit into it's internal buffer, it will deadlock. ThreadedFileWriter::Write() will block waiting for BufFree?() to be greater than the data to be written, but that will never happen.

The attached patch creates a loop in ThreadedFileWriter::Write() to process the fed data into the internal buffer as space becomes available. This can cause ThreadedFileWriter::Write() to take longer to return, but as long as the recorder has a big enough buffer (or uses DeviceReadBuffer?), then it should not be a problem.

The other option is for ThreadedFileWriter::Write() to only process as much as it can in one pass, then return that amount to the calling function. However, this causes a problem with keyframes. Since "recorders" need to note the position in the file where keyrframes are written, if they don't actually get written, then the position would be wrong.

I found this problem with recording from the HD-PVR. I was experiencing deadlocks in about 1:10 recordings.

Attachments (3)

ThreadedFileWriter-deadlock.patch (3.1 KB) - added by jppoet@… 16 years ago.
Fix deadlock in ThreadedFileWriter::Write()
ThreadedFileWriter-deadlock-v1.1.patch (3.1 KB) - added by jppoet@… 16 years ago.
Re-order some statements for efficiency.
5591-v2.patch (3.6 KB) - added by danielk 16 years ago.
updated patch

Download all attachments as: .zip

Change History (6)

Changed 16 years ago by jppoet@…

Fix deadlock in ThreadedFileWriter::Write()

Changed 16 years ago by jppoet@…

Re-order some statements for efficiency.

comment:1 Changed 16 years ago by jppoet@…

The original patch could execute the loop with no data, causing a mutex wait when no data was ready to be processed.

New patch added which fixes that.

comment:2 Changed 16 years ago by danielk

(In [18100]) Refs #5591. Finish porting TFW to Qt4.

The TFW was given temporary do nothing mutexes as part of the porting process, this uses the buflock mutex instead and reorganizes the code a bit to be more Qt4 friendly.

Changed 16 years ago by danielk

Attachment: 5591-v2.patch added

updated patch

comment:3 Changed 16 years ago by danielk

Resolution: fixed
Status: newclosed

(In [18105]) Fixes #5591. Fixes a deadlock on very large writes to the ThreadedFileWriter?.

Note: See TracTickets for help on using tickets.