From 51f0883b6493f3454bb7244bfc676236280d9d52 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Tue, 23 Oct 2018 17:17:23 +0200 Subject: [PATCH] Fix race condition The streaming thread might end before the merge thread. In that case the download would terminate before all data has been written. --- .../java/ctbrec/recorder/download/MergedHlsDownload.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ctbrec/recorder/download/MergedHlsDownload.java b/src/main/java/ctbrec/recorder/download/MergedHlsDownload.java index 20d726d1..f122b895 100644 --- a/src/main/java/ctbrec/recorder/download/MergedHlsDownload.java +++ b/src/main/java/ctbrec/recorder/download/MergedHlsDownload.java @@ -1,7 +1,6 @@ package ctbrec.recorder.download; -import static java.nio.file.StandardOpenOption.CREATE; -import static java.nio.file.StandardOpenOption.WRITE; +import static java.nio.file.StandardOpenOption.*; import java.io.ByteArrayInputStream; import java.io.EOFException; @@ -66,10 +65,13 @@ public class MergedHlsDownload extends AbstractHlsDownload { mergeThread = createMergeThread(targetFile, progressListener, false); mergeThread.start(); downloadSegments(segmentPlaylistUri, false); + mergeThread.join(); } catch(ParseException e) { throw new IOException("Couldn't parse stream information", e); } catch(PlaylistException e) { throw new IOException("Couldn't parse HLS playlist", e); + } catch (InterruptedException e) { + throw new IOException("Couldn't wait for write thread to finish. Recording might be cut off", e); } finally { alive = false; streamer.stop();