Re: hung in read$UNIX2003
Re: hung in read$UNIX2003
- Subject: Re: hung in read$UNIX2003
- From: Michael Ash <email@hidden>
- Date: Fri, 3 Apr 2009 12:10:33 -0400
On Fri, Apr 3, 2009 at 9:36 AM, Michael Domino
<email@hidden> wrote:
> Hi all,
>
> I have a task prepared and launched with the code below, and when it returns
> (in this situation that status code returned from terminationStatus is 0),
> it hangs in availableData, never to return. The stack at this point is very
> deep because of a recursive function (see the stack trace below), which
> might be a factor in this hanging problem. Could this be a problem with the
> stack depth? This code functions perfectly most of the time.
>
> messagePipeError = [NSPipe pipe];
> messagePipeOutput = [NSPipe pipe];
> [task setLaunchPath:@"/usr/bin/hdiutil"];
> [task setArguments:[NSArray
> arrayWithObjects:@"info", nil]];
> [task setStandardError:messagePipeError];
>
> [task setStandardOutput:messagePipeOutput];
>
> [task launch];
> [task waitUntilExit];
> status = [task terminationStatus];
>
> NSData *messageDataError = [[messagePipeError
> fileHandleForReading] availableData];
> messageError = [[[NSString alloc]
> initWithData:messageDataError encoding:NSUTF8StringEncoding] autorelease];
I don't know if this is the cause of your problem or not, but never,
ever do this. Don't call waitUntilExit before you read. Pipes have a
small buffer (4kB?) and if it fills up then further writes will block.
This means that if you do a waitUntilExit while the subprocess is
writing more data than the pipe can buffer, you'll deadlock. The
subprocess will be waiting for you to read data before it can
continue, and you will be waiting for it to exit before you read data.
Read all data (using readDataToEndOfFile or equivalent) *before* you
do waitUntilExit.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden