0

In my macOS app I launch the ffmpeg task in order to retrieve the media file information.

And I receive many crashes due to EXC_GUARD:

Exception Type:        EXC_GUARD
Exception Codes:       0x4000000200000001, 0xd71a2ae8e8dab339
Exception Subtype:     GUARD_TYPE_FD, id=0xd71a2ae8e8dab339, fd=1, flavor=0x00000002 (DUP)

Here is the code I use:

    NSArray *ffmpegArgs = [NSArray arrayWithObjects:@"-hide_banner", @"-nostdin", @"-nostats",
                           @"-i", self.media.path,
                           nil];
    self.task = [[NSTask alloc] init];
    [self.task setLaunchPath:[[NSBundle mainBundle] pathForResource:@"ffmpeg" ofType:nil]];
    [self.task setArguments:ffmpegArgs];
    NSPipe *errorPipe = [NSPipe pipe];
    self.task.standardError = errorPipe;
    NSFileHandle *errorHandle = [errorPipe fileHandleForReading];
    @try {
        [self.task launch];
    } @catch (NSException *exception) {
        NSLog(@"An exception %@ was thrown while attempting to launch the ffmpeg task with arguments: %@.", exception.description, [ffmpegArgs componentsJoinedByString:@" "]);
        [errorHandle closeFile];
        return;
    }
    [self.task waitUntilExit];
    NSData *outputData = [errorHandle readDataToEndOfFile];
    [errorHandle closeFile];

I can't reproduce this crash on my device.

Can anyone help me?

Viktoriia
  • 71
  • 6
  • This is due to a file descriptor conflict. Please read this answer: https://stackoverflow.com/questions/32429431/exc-guard-exception – jvarela Aug 19 '20 at 09:48
  • @jvarela, thank you very much for your response. But I don't understand what may cause this conflict. I have been using this code for several years. And everything worked fine until recently. Why does the stdout descriptor (fd=1) cause the conflict? Can you clarify me? Thanks in advance. – Viktoriia Aug 19 '20 at 10:50
  • Can you check what happens if you do not call closeFile? Perhaps, there is a bug on macOS or in the ffmpeg process that is causing this. – jvarela Aug 19 '20 at 12:45
  • Initially I did not call closeFile, but after I received many crashes from users, I decided that these crashes are related to running out of file handles (see http://openradar.appspot.com/radar?id=1387401). That's why I added the closeFile call. But this fix did not solve the problem and I still receive crashes that I can't reproduce. – Viktoriia Aug 19 '20 at 14:48
  • Also I use the Sparkle updater (https://sparkle-project.org/) in my app and receive the same crashes when Sparkle launches its tasks. – Viktoriia Aug 19 '20 at 15:15

0 Answers0