Projects

Ticket #540 (closed defect: fixed)

Opened 2 years ago

Last modified 14 months ago

segfault with NSURLDownload with GC on

Reported by: mattaimonetti@… Owned by: lsansonetti@…
Priority: major Milestone: MacRuby 0.8
Component: MacRuby Keywords: NSURLDownload, Cocoa
Cc:

Description (last modified by mattaimonetti@…) (diff)

Script:  https://gist.github.com/96954a4e59f1293977c0

Backtrace:

Application Specific Information:
objc_msgSend() selector name: _downloadActive
objc[74889]: garbage collection is ON

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib               	0x00007fff8821011c objc_msgSend + 40
1   com.apple.Foundation          	0x00007fff84db156d _NSURLDownloadDidReceiveData + 45
2   com.apple.CFNetwork           	0x00007fff8143b50f URLDownload::sendClientDidReceiveData(long, long, long) + 83
3   com.apple.CFNetwork           	0x00007fff8143cd9c ___asyncWrite_block_invoke_4 + 121
4   com.apple.CoreFoundation      	0x00007fff8060c1b9 __CFRunLoopDoBlocks + 297
5   com.apple.CoreFoundation      	0x00007fff805cece6 __CFRunLoopRun + 3046
6   com.apple.CoreFoundation      	0x00007fff805cdc2f CFRunLoopRunSpecific + 575
7   com.apple.Foundation          	0x00007fff84c94a24 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 270
8   com.apple.Foundation          	0x00007fff84ce048a -[NSRunLoop(NSRunLoop) runUntilDate:] + 78
9   ???                           	0x00000001011005fc 0 + 4312794620

Thread 1:  Dispatch queue: com.apple.libdispatch-manager
0   libSystem.B.dylib             	0x00007fff8650cbba kevent + 10
1   libSystem.B.dylib             	0x00007fff8650ea85 _dispatch_mgr_invoke + 154
2   libSystem.B.dylib             	0x00007fff8650e75c _dispatch_queue_invoke + 185
3   libSystem.B.dylib             	0x00007fff8650e286 _dispatch_worker_thread2 + 244
4   libSystem.B.dylib             	0x00007fff8650dbb8 _pthread_wqthread + 353
5   libSystem.B.dylib             	0x00007fff8650da55 start_wqthread + 13

Thread 2:
0   libSystem.B.dylib             	0x00007fff8650d9da __workq_kernreturn + 10
1   libSystem.B.dylib             	0x00007fff8650ddec _pthread_wqthread + 917
2   libSystem.B.dylib             	0x00007fff8650da55 start_wqthread + 13

Thread 3:
0   libSystem.B.dylib             	0x00007fff8650d9da __workq_kernreturn + 10
1   libSystem.B.dylib             	0x00007fff8650ddec _pthread_wqthread + 917
2   libSystem.B.dylib             	0x00007fff8650da55 start_wqthread + 13

Thread 4:
0   libSystem.B.dylib             	0x00007fff864f3e3a mach_msg_trap + 10
1   libSystem.B.dylib             	0x00007fff864f44ad mach_msg + 59
2   com.apple.CoreFoundation      	0x00007fff805ce7a2 __CFRunLoopRun + 1698
3   com.apple.CoreFoundation      	0x00007fff805cdc2f CFRunLoopRunSpecific + 575
4   com.apple.Foundation          	0x00007fff84cd94cf +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 297
5   com.apple.Foundation          	0x00007fff84c59e99 __NSThread__main__ + 1429
6   libSystem.B.dylib             	0x00007fff8652cf8e _pthread_start + 331
7   libSystem.B.dylib             	0x00007fff8652ce41 thread_start + 13

Thread 5:
0   libSystem.B.dylib             	0x00007fff8650d9da __workq_kernreturn + 10
1   libSystem.B.dylib             	0x00007fff8650ddec _pthread_wqthread + 917
2   libSystem.B.dylib             	0x00007fff8650da55 start_wqthread + 13

Thread 6:
0   libSystem.B.dylib             	0x00007fff865379e2 select$DARWIN_EXTSN + 10
1   com.apple.CoreFoundation      	0x00007fff805f0242 __CFSocketManager + 818
2   libSystem.B.dylib             	0x00007fff8652cf8e _pthread_start + 331
3   libSystem.B.dylib             	0x00007fff8652ce41 thread_start + 13

works fine with GC_DISABLE=1

---

TODO: Rewrite the script in pure objc, compile with -fobjc-gc and see if it's a MacRuby bug or a Cocoa bug.

Change History

Changed 2 years ago by mattaimonetti@…

  • owner changed from mattaimonetti@… to lsansonetti@…
  • keywords NSURLDownload, Cocoa added
  • description modified (diff)

ported to obj-c and everything works fine even with the GC on:

#import <Foundation/Foundation.h>

@interface Test : NSObject
@end

@implementation Test
-(void)startDownload{
  NSString *url_string = @"http://macruby.icoretech.org/latest";
  NSURL *url = [NSURL URLWithString: url_string];
  NSURLRequest *req = [NSURLRequest requestWithURL: url];

  [[NSURLDownload alloc] initWithRequest: req delegate: self];
}

- (void)downloadDidFinish:(NSURLDownload *)download
{
    NSLog(@"Download finished!");
    exit(0);
}

@end


int main (void) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    [[Test alloc] startDownload];
    NSLog(@"Hello, Laurent");  
    
    [[NSRunLoop currentRunLoop] runUntilDate: [NSDate distantFuture]];
    [pool drain];
    return 0;
}

Note that the MacRuby script works fine on small files but seems to fail on big files (at least the latest pkg)

Changed 2 years ago by chapbr@…

One potential issue with the macruby example code is passing 'self' as the delegate to the NSURLDownload instance. Maybe it's supposed to work, but since the delegate methods are defined in the top level namespace, I wasn't sure what the self instance actually refers to (?):

$ macruby -e 'p self' # => main
$ macruby -e 'p self.class' #=> TopLevel

I modified the gist example code to move the delegate methods inside of a Test class and then passed an instance of that class as the delegate to NSURLDownload. The new version no longer crashes during download:

 https://gist.github.com/d5d8f8a5208fa4a4d94c

Changed 14 months ago by isaackearse@…

After changing the URL to the new nightly macruby package this works for me with GC on. See this updated gist revision:  https://gist.github.com/d711103f30fe6ef42323/2a24d210b7504da8a910228ea898ee760e50053f

git clone git@gist.github.com:d711103f30fe6ef42323.git gist-d711103f
cd gist-d711103f
macruby gistfile1.rb

downloading...
Download finished!

Changed 14 months ago by lsansonetti@…

  • status changed from new to closed
  • resolution set to fixed
  • milestone changed from MacRuby 0.5 to MacRuby 0.8

I also tried the script and it worked for me without crashing. So I assume something was fixed since. Closing the bug.

Note: See TracTickets for help on using tickets.