NSURLDownload mysteriously pausing

1 view
Skip to first unread message

Sidney San Martín

unread,
Feb 16, 2011, 2:00:26 PM2/16/11
to coco...@lists.apple.com
Greetings!
I ran into an issue recently where file downloads seemed to take a ridiculous amount of time to finish, or never finished at all. I could reproduce it, even in a stripped-down test application.

The NSURLDownload appears to pause indefinitely whenever there is no other activity in the application. Any activity at all — a key press while the application is in front, moving a window around, etc. — makes it continue for a short amount of time (which can be observed in the log or in Activity Monitor's network activity graph).

Below is the main class of a test application with a main class called downloaderAppDelegate. The issue's reproducible for me by dropping it into a new Xcode Cocoa application project.

What the heck is going on?
-Sidney

@implementation downloaderAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NSURLDownload alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"ftp://ftp1.optonline.net/test64"]] delegate:self];
}
#pragma mark NSURLDownload delegate methods
- (void)download:(NSURLDownload *)download didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Response: %@", response);
}
- (void)download:(NSURLDownload *)d didReceiveDataOfLength:(NSUInteger)length
{
NSLog(@"received %d", length);
}
- (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSString *)name
{
[d setDestination:[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/testDownload"] allowOverwrite:NO];
}
- (void)downloadDidFinish:(NSURLDownload *)d
{
NSLog(@"Download complete");
exit(0);
}
- (void)download:(NSURLDownload *)d didFailWithError:(NSError *)error
{
NSLog(@"Failed to download (%@)", [error localizedDescription]);
exit(0);
}
@end
_______________________________________________

Cocoa-dev mailing list (Coco...@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/cocoa-dev-garchive-98506%40googlegroups.com

This email sent to cocoa-dev-ga...@googlegroups.com

Michael Babin

unread,
Feb 18, 2011, 9:14:44 AM2/18/11
to Sidney San Martín, coco...@lists.apple.com
On Feb 16, 2011, at 1:00 PM, Sidney San Martín wrote:

> Greetings!
> I ran into an issue recently where file downloads seemed to take a ridiculous amount of time to finish, or never finished at all. I could reproduce it, even in a stripped-down test application.
>
> The NSURLDownload appears to pause indefinitely whenever there is no other activity in the application. Any activity at all — a key press while the application is in front, moving a window around, etc. — makes it continue for a short amount of time (which can be observed in the log or in Activity Monitor's network activity graph).
>
> Below is the main class of a test application with a main class called downloaderAppDelegate. The issue's reproducible for me by dropping it into a new Xcode Cocoa application project.
>
> What the heck is going on?

To quote from:

<http://developer.apple.com/library/mac/#documentation/cocoa/reference/Foundation/Classes/NSURLDownload_Class/Reference/Reference.html>

"For the download to work correctly the calling thread’s run loop must be operating in the default run loop mode."

Doing anything out of the ordinary with the run loop?

- Mike

Sidney San Martín

unread,
Feb 18, 2011, 9:23:28 AM2/18/11
to coco...@lists.apple.com
On Fri, Feb 18, 2011 at 9:14 AM, Michael Babin <mba...@orderndev.com> wrote:

> On Feb 16, 2011, at 1:00 PM, Sidney San Martín wrote:
>
> > Greetings!
> > I ran into an issue recently where file downloads seemed to take a
> ridiculous amount of time to finish, or never finished at all. I could
> reproduce it, even in a stripped-down test application.
> >
> > The NSURLDownload appears to pause indefinitely whenever there is no
> other activity in the application. Any activity at all — a key press while
> the application is in front, moving a window around, etc. — makes it
> continue for a short amount of time (which can be observed in the log or in
> Activity Monitor's network activity graph).
> >
> > Below is the main class of a test application with a main class called
> downloaderAppDelegate. The issue's reproducible for me by dropping it into a
> new Xcode Cocoa application project.
> >
> > What the heck is going on?
>
> To quote from:
>
> <
> http://developer.apple.com/library/mac/#documentation/cocoa/reference/Foundation/Classes/NSURLDownload_Class/Reference/Reference.html
> >
>
> "For the download to work correctly the calling thread’s run loop must be
> operating in the default run loop mode."
>
> Doing anything out of the ordinary with the run loop?
>
> - Mike
>

Hey, Mike.
That's a good point, but the above code reproduces the issue for me on a
vanilla Cocoa project — no runloop weirdness.

Joar Wingfors

unread,
Feb 18, 2011, 10:47:03 PM2/18/11
to Sidney San Martín, coco...@lists.apple.com

On 16 feb 2011, at 11.00, Sidney San Martín wrote:

> Below is the main class of a test application with a main class called downloaderAppDelegate. The issue's reproducible for me by dropping it into a new Xcode Cocoa application project.


I've not been able to reproduce that issue (with the provided URL, or any other URL). I tried it on Mac OS X 10.6.6.

j o a r

Reply all
Reply to author
Forward
0 new messages