Changeset 212198 in webkit
- Timestamp:
- Feb 11, 2017 8:10:20 PM (7 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r212183 r212198 1 2017-02-11 Alex Christensen <achristensen@webkit.org> 2 3 Fix crashes after [NSURLSession invalidateAndCancel] 4 https://bugs.webkit.org/show_bug.cgi?id=168181 5 <rdar://problem/29813868> 6 7 Reviewed by Brady Eidson. 8 9 When we call NetworkSessionCocoa::invalidateAndCancel, we intend for the session to immediately 10 become invalid and stop doing things. [NSURLSession invalidateAndCancel] asynchronously cancels 11 everything and then calls the delegate's didBecomeInvalidWithError, so before this change there 12 is a time when we have torn down the session with SessionTracker::destroySession but we can still 13 get a delegate callback which assumes the session and its NetworkStorageSession exists. If we 14 get any delegate callbacks after a NetworkSession has been invalidated, we will want to ignore them. 15 16 * NetworkProcess/cocoa/NetworkSessionCocoa.mm: 17 (-[WKNetworkSessionDelegate sessionInvalidated]): 18 (-[WKNetworkSessionDelegate URLSession:didBecomeInvalidWithError:]): 19 (-[WKNetworkSessionDelegate URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:]): 20 (-[WKNetworkSessionDelegate URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]): 21 (-[WKNetworkSessionDelegate URLSession:task:_schemeUpgraded:completionHandler:]): 22 (-[WKNetworkSessionDelegate URLSession:task:didReceiveChallenge:completionHandler:]): 23 (-[WKNetworkSessionDelegate URLSession:task:didCompleteWithError:]): 24 (-[WKNetworkSessionDelegate URLSession:dataTask:didReceiveResponse:completionHandler:]): 25 (-[WKNetworkSessionDelegate URLSession:dataTask:didReceiveData:]): 26 (-[WKNetworkSessionDelegate URLSession:downloadTask:didFinishDownloadingToURL:]): 27 (-[WKNetworkSessionDelegate URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:]): 28 (-[WKNetworkSessionDelegate URLSession:downloadTask:didResumeAtOffset:expectedTotalBytes:]): 29 (-[WKNetworkSessionDelegate URLSession:dataTask:didBecomeDownloadTask:]): 30 The pointer to the NetworkSessionCocoa can now be null. We need to check it. 31 (WebKit::NetworkSessionCocoa::invalidateAndCancel): 32 Synchronously remove the connection between the delegates and the NetworkSessionCocoa. 33 1 34 2017-02-10 John Wilander <wilander@apple.com> 2 35 -
trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm
r211751 r212198 88 88 89 89 - (id)initWithNetworkSession:(WebKit::NetworkSessionCocoa&)session withCredentials:(bool)withCredentials; 90 - (void)sessionInvalidated; 90 91 91 92 @end … … 105 106 } 106 107 108 - (void)sessionInvalidated 109 { 110 _session = nullptr; 111 } 112 107 113 - (void)URLSession:(NSURLSession *)session didBecomeInvalidWithError:(nullable NSError *)error 108 114 { 109 _session = nullptr;115 ASSERT(!_session); 110 116 } 111 117 112 118 - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend 113 119 { 120 if (!_session) 121 return; 122 114 123 auto storedCredentials = _withCredentials ? WebCore::StoredCredentials::AllowStoredCredentials : WebCore::StoredCredentials::DoNotAllowStoredCredentials; 115 124 if (auto* networkDataTask = _session->dataTaskForIdentifier(task.taskIdentifier, storedCredentials)) … … 119 128 - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest *))completionHandler 120 129 { 130 if (!_session) { 131 completionHandler(nil); 132 return; 133 } 134 121 135 auto taskIdentifier = task.taskIdentifier; 122 136 LOG(NetworkSession, "%llu willPerformHTTPRedirection from %s to %s", taskIdentifier, response.URL.absoluteString.UTF8String, request.URL.absoluteString.UTF8String); … … 138 152 - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask*)task _schemeUpgraded:(NSURLRequest*)request completionHandler:(void (^)(NSURLRequest*))completionHandler 139 153 { 154 if (!_session) { 155 completionHandler(nil); 156 return; 157 } 158 140 159 auto taskIdentifier = task.taskIdentifier; 141 160 LOG(NetworkSession, "%llu _schemeUpgraded %s", taskIdentifier, request.URL.absoluteString.UTF8String); … … 157 176 - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask willCacheResponse:(NSCachedURLResponse *)proposedResponse completionHandler:(void (^)(NSCachedURLResponse * _Nullable cachedResponse))completionHandler 158 177 { 178 if (!_session) { 179 completionHandler(nil); 180 return; 181 } 182 159 183 // FIXME: remove if <rdar://problem/20001985> is ever resolved. 160 184 if ([proposedResponse.response respondsToSelector:@selector(allHeaderFields)] … … 167 191 - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler 168 192 { 193 if (!_session) { 194 completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil); 195 return; 196 } 197 169 198 auto taskIdentifier = task.taskIdentifier; 170 199 LOG(NetworkSession, "%llu didReceiveChallenge", taskIdentifier); … … 208 237 - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error 209 238 { 239 if (!_session) 240 return; 241 210 242 LOG(NetworkSession, "%llu didCompleteWithError %@", task.taskIdentifier, error); 211 243 auto storedCredentials = _withCredentials ? WebCore::StoredCredentials::AllowStoredCredentials : WebCore::StoredCredentials::DoNotAllowStoredCredentials; … … 233 265 - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler 234 266 { 267 if (!_session) { 268 completionHandler(NSURLSessionResponseCancel); 269 return; 270 } 271 235 272 auto taskIdentifier = dataTask.taskIdentifier; 236 273 LOG(NetworkSession, "%llu didReceiveResponse", taskIdentifier); … … 266 303 - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data 267 304 { 305 if (!_session) 306 return; 307 268 308 auto storedCredentials = _withCredentials ? WebCore::StoredCredentials::AllowStoredCredentials : WebCore::StoredCredentials::DoNotAllowStoredCredentials; 269 309 if (auto* networkDataTask = _session->dataTaskForIdentifier(dataTask.taskIdentifier, storedCredentials)) … … 273 313 - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location 274 314 { 315 if (!_session) 316 return; 317 275 318 auto downloadID = _session->takeDownloadID([downloadTask taskIdentifier]); 276 319 if (auto* download = WebKit::NetworkProcess::singleton().downloadManager().download(downloadID)) … … 280 323 - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite 281 324 { 325 if (!_session) 326 return; 327 282 328 auto storedCredentials = _withCredentials ? WebCore::StoredCredentials::AllowStoredCredentials : WebCore::StoredCredentials::DoNotAllowStoredCredentials; 283 329 ASSERT_WITH_MESSAGE_UNUSED(storedCredentials, !_session->dataTaskForIdentifier([downloadTask taskIdentifier], storedCredentials), "The NetworkDataTask should be destroyed immediately after didBecomeDownloadTask returns"); … … 290 336 - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes 291 337 { 338 if (!_session) 339 return; 340 292 341 notImplemented(); 293 342 } … … 295 344 - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask 296 345 { 346 if (!_session) 347 return; 348 297 349 auto storedCredentials = _withCredentials ? WebCore::StoredCredentials::AllowStoredCredentials : WebCore::StoredCredentials::DoNotAllowStoredCredentials; 298 350 if (auto* networkDataTask = _session->dataTaskForIdentifier([dataTask taskIdentifier], storedCredentials)) { … … 470 522 [m_sessionWithCredentialStorage invalidateAndCancel]; 471 523 [m_sessionWithoutCredentialStorage invalidateAndCancel]; 472 } 473 524 [m_sessionWithCredentialStorageDelegate sessionInvalidated]; 525 [m_sessionWithoutCredentialStorageDelegate sessionInvalidated]; 526 } 474 527 475 528 void NetworkSessionCocoa::clearCredentials()
Note: See TracChangeset
for help on using the changeset viewer.