-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task created in a session that has been invalidated #22410
Comments
Can you run If you believe this information is irrelevant to the reported issue, you may write |
I am closing this issue because it does not contain the necessary environment info, and there has been no followup in a while. If you found this thread after encountering the same issue in the latest release, please feel free to create a new issue with up-to-date information by clicking here. |
Summary: Fix crash similar to #22410 react-native: 0.51.0 react: 16.0.0 Changelog: ---------- [iOS] [Changed] - Use onw serial queue to execute invalidate and send request action in RCTHTTPRequestHandler.mm. Message: -------- ``` - (void)invalidate { [_session invalidateAndCancel]; _session = nil; } - (NSURLSessionDataTask *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate>)delegate { // Lazy setup if (!_session && [self isValid]) { NSOperationQueue *callbackQueue = [NSOperationQueue new]; callbackQueue.maxConcurrentOperationCount = 1; callbackQueue.underlyingQueue = [[_bridge networking] methodQueue]; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; [configuration setHTTPShouldSetCookies:YES]; [configuration setHTTPCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; [configuration setHTTPCookieStorage:[NSHTTPCookieStorage sharedHTTPCookieStorage]]; _session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:callbackQueue]; std::lock_guard<std::mutex> lock(_mutex); _delegates = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsStrongMemory valueOptions:NSPointerFunctionsStrongMemory capacity:0]; } NSURLSessionDataTask *task = [_session dataTaskWithRequest:request]; { std::lock_guard<std::mutex> lock(_mutex); [_delegates setObject:delegate forKey:task]; } [task resume]; return task; } ``` now the invalidate function is called by the RCTBridge.invalidate->RCTCxxBridge.invalidate->[moduleData.instance invalidate] , this is on the "com.facebook.react.HTTPRequestHandlerQueue". the sendRequest:withDelegate function is called by RCTImageLoader and is on the "com.facebook.react.imageLoaderURLRequestQueue". when one thread step in invalidate and execute [_session invalidateAndCancel] and the another thread step in sendRequest:withDelegate and execute [_session dataTaskWithRequest:request], the _session is invalidate, so there will be a crash "Task created in a session that has been invalidated" Pull Request resolved: #22746 Differential Revision: D13781512 Pulled By: cpojer fbshipit-source-id: bd5fd1edf593e2bcdcc18596a29e906882bac8a4
Summary: Fix crash similar to facebook#22410 react-native: 0.51.0 react: 16.0.0 Changelog: ---------- [iOS] [Changed] - Use onw serial queue to execute invalidate and send request action in RCTHTTPRequestHandler.mm. Message: -------- ``` - (void)invalidate { [_session invalidateAndCancel]; _session = nil; } - (NSURLSessionDataTask *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate>)delegate { // Lazy setup if (!_session && [self isValid]) { NSOperationQueue *callbackQueue = [NSOperationQueue new]; callbackQueue.maxConcurrentOperationCount = 1; callbackQueue.underlyingQueue = [[_bridge networking] methodQueue]; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; [configuration setHTTPShouldSetCookies:YES]; [configuration setHTTPCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; [configuration setHTTPCookieStorage:[NSHTTPCookieStorage sharedHTTPCookieStorage]]; _session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:callbackQueue]; std::lock_guard<std::mutex> lock(_mutex); _delegates = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsStrongMemory valueOptions:NSPointerFunctionsStrongMemory capacity:0]; } NSURLSessionDataTask *task = [_session dataTaskWithRequest:request]; { std::lock_guard<std::mutex> lock(_mutex); [_delegates setObject:delegate forKey:task]; } [task resume]; return task; } ``` now the invalidate function is called by the RCTBridge.invalidate->RCTCxxBridge.invalidate->[moduleData.instance invalidate] , this is on the "com.facebook.react.HTTPRequestHandlerQueue". the sendRequest:withDelegate function is called by RCTImageLoader and is on the "com.facebook.react.imageLoaderURLRequestQueue". when one thread step in invalidate and execute [_session invalidateAndCancel] and the another thread step in sendRequest:withDelegate and execute [_session dataTaskWithRequest:request], the _session is invalidate, so there will be a crash "Task created in a session that has been invalidated" Pull Request resolved: facebook#22746 Differential Revision: D13781512 Pulled By: cpojer fbshipit-source-id: bd5fd1edf593e2bcdcc18596a29e906882bac8a4
Environment
[skip envinfo]
OS Version: iOS 9,10,11,12
react-native Version: 0.50.4
Description
We got this crash long ago, but only recently there is a significant increase on this crash because we use more react native pages in our app.
Here is the call stack of the crash
below is the iOS versions this crash occurs.
Any other infos need from this crash? I'll later add on.
The text was updated successfully, but these errors were encountered: