Skip to content

Commit

Permalink
Add process exit check to mitigate possible .NET bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Nov 28, 2023
1 parent 4403b5d commit 99d60a1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions TwitchDownloaderCore/ClipDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ void DownloadProgressHandler(StreamCopyProgress streamProgress)
var clipChapter = TwitchHelper.GenerateClipChapter(clipInfo.data.clip);
await EncodeClipWithMetadata(tempFile, downloadOptions.Filename, clipInfo.data.clip, clipChapter, cancellationToken);

if (!File.Exists(downloadOptions.Filename))
{
File.Move(tempFile, downloadOptions.Filename);
throw new FileNotFoundException("Unable to serialize metadata (is FFmpeg missing?). The download has been completed without custom metadata.");
}

_progress.Report(new ProgressReport(ReportType.SameLineStatus, "Encoding Clip Metadata 100%"));
_progress.Report(new ProgressReport(100));
}
Expand Down Expand Up @@ -163,6 +169,12 @@ await FfmpegMetadata.SerializeAsync(metadataFile, clipMetadata.broadcaster.displ
};

process.Start();

// If the process has exited before we call WaitForExitAsync, the thread locks up.
// This was probably not intended by the .NET team, but it's an issue regardless.
if (process.HasExited)
return;

await process.WaitForExitAsync(cancellationToken);
}
finally
Expand Down

0 comments on commit 99d60a1

Please sign in to comment.