Hopefully fixed some deadlocks

This commit is contained in:
0xboobface 2019-06-03 21:16:35 +02:00
parent b136fce0db
commit 645f0b8231
3 changed files with 27 additions and 21 deletions

View File

@ -411,18 +411,20 @@ public class NextGenLocalRecorder implements Recorder {
for (Recording rec : toStop) { for (Recording rec : toStop) {
Optional.ofNullable(rec.getDownload()).ifPresent(Download::stop); Optional.ofNullable(rec.getDownload()).ifPresent(Download::stop);
} }
} finally {
recordingsLock.unlock();
}
// wait for post-processing to finish // wait for post-processing to finish
LOG.info("Waiting for downloads to finish"); LOG.info("Waiting for downloads to finish");
while (!recordingProcesses.isEmpty()) { for (int i = 0; i < 60; i++) {
if (!recordingProcesses.isEmpty()) {
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOG.error("Error while waiting for downloads to finish", e); LOG.error("Error while waiting for downloads to finish", e);
} }
} }
} finally {
recordingsLock.unlock();
} }
// shutdown threadpools // shutdown threadpools

View File

@ -237,14 +237,16 @@ public class HlsDownload extends AbstractHlsDownload {
} }
@Override @Override
public void stop() { public synchronized void stop() {
internalStop(); if (running) {
try { internalStop();
synchronized (downloadFinished) { try {
downloadFinished.wait(); synchronized (downloadFinished) {
downloadFinished.wait();
}
} catch (InterruptedException e) {
LOG.error("Couldn't wait for download to finish", e);
} }
} catch (InterruptedException e) {
LOG.error("Couldn't wait for download to finish", e);
} }
} }

View File

@ -374,17 +374,19 @@ public class MergedHlsDownload extends AbstractHlsDownload {
} }
@Override @Override
public void stop() { public synchronized void stop() {
internalStop(); if (running) {
try { internalStop();
synchronized (downloadFinished) { try {
LOG.debug("Waiting for finished notify {}", model); synchronized (downloadFinished) {
downloadFinished.wait(); LOG.debug("Waiting for finished notify {}", model);
downloadFinished.wait();
}
} catch (InterruptedException e) {
LOG.error("Couldn't wait for download to finish", e);
} }
} catch (InterruptedException e) { LOG.debug("Download stopped");
LOG.error("Couldn't wait for download to finish", e);
} }
LOG.debug("Download stopped");
} }
@Override @Override