2

私は IOS を初めて使用しましたが、バグに遭遇したのか、何か間違ったことをしているのかまだわかりません。私が得た奇妙な動作を考えると、これは IOS が接続を再利用しようとする方法のバグだと思う傾向があります。誰かがこれについて知っているかどうか、そして回避策があるかどうか疑問に思います。

IOS 6.1 ARC が有効なシミュレーターで発生します。さらに奇妙なことに、電話でクラッシュさせることができないので、これを恐れるべきかどうか疑問に思っています。

複数の同時 http 接続を実行しています。接続が終了または失敗すると、新しい接続を開始します。今まで私は3つの状況を持っています:

ケース 1: サーバーが存在し、動作し、各要求が成功し、動作します。

ケース 2: サーバーは存在しますが、指定されたポートをリッスンしません。

ケース 3: サーバーがオフライン (マシンがダウンしているなど) で、100 ~ 2000 のリクエスト後にクラッシュします。

編集: NicholasHartの提案に従ってコードを変更しましたが、問題は解決しません

#import "ViewController.h"

@interface ViewController ()
{
    NSURLRequest *request;
}
@end

@implementation ViewController

- (IBAction)test:(id)sender {
    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.1.178:8888/r.php"]
                                                    cachePolicy:NSURLCacheStorageNotAllowed
                                                timeoutInterval:10.0];
    NSLog(@"starting %@", [NSThread currentThread]);
    NSURLConnection *conn;

    for(int i=0;i<6;i++) conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

#pragma mark NSURLConnection Delegate Methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {}
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse*)cachedResponse {return nil;}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    //[connection cancel]; //not needed, suggested by NicholasHart
    NSLog(@"ok %@", [NSThread currentThread]);
    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    //[connection cancel]; //not needed, suggested by NicholasHart
    NSLog(@"error %@", [NSThread currentThread]);
    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
@end

ケース 3 の場合、次のようなさまざまなクラッシュがあります。


libdispatch.dylib`_dispatch_retain:
0x49f98f0:  movl   4(%esp), %eax
0x49f98f4:  cmpl   $2147483647, 4(%eax)
0x49f98fb:  je     0x49f9910                 ; _dispatch_retain + 32
0x49f98fd:  addl   $4, %eax
0x49f9900:  movl   $1, %ecx
0x49f9905:  lock
0x49f9906:  xaddl  %ecx, (%eax)
0x49f9909:  incl   %ecx
0x49f990a:  testl  %ecx, %ecx
0x49f990c:  jg     0x49f9910                 ; _dispatch_retain + 32
0x49f990e:  ud2
0x49f9910:  ret
4

0 に答える 0