Skip to content

Commit 0bd7b4e

Browse files
cipolleschireact-native-bot
authored andcommitted
Back out "fix: avoid race condition crash in [RCTDataRequestHandler invalidate]" (#49797)
Summary: Pull Request resolved: #49797 Backing D70314889 as it was breaking some internal tests. I verified that before the backout the tests were failing and after the backout they were not. ## Changelog: [iOS][Changed] - Reverted fix: avoid race condition crash in [RCTDataRequestHandler invalidate]. Reviewed By: Abbondanzo Differential Revision: D70511155 fbshipit-source-id: 276f6947aa6bb648c9c9eeb5c342f336acc8a26f
1 parent adb3bee commit 0bd7b4e

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

packages/react-native/Libraries/Network/RCTDataRequestHandler.mm

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,8 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ
4949
_queue.maxConcurrentOperationCount = 2;
5050
}
5151

52-
__weak NSBlockOperation *weakOp;
53-
NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{
54-
NSBlockOperation *strongOp = weakOp; // Strong reference to avoid deallocation during execution
55-
if (strongOp == nil || [strongOp isCancelled]) {
56-
return;
57-
}
58-
52+
__weak __block NSBlockOperation *weakOp;
53+
__block NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{
5954
// Get mime type
6055
NSRange firstSemicolon = [request.URL.resourceSpecifier rangeOfString:@";"];
6156
NSString *mimeType =
@@ -67,15 +62,15 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ
6762
expectedContentLength:-1
6863
textEncodingName:nil];
6964

70-
[delegate URLRequest:strongOp didReceiveResponse:response];
65+
[delegate URLRequest:weakOp didReceiveResponse:response];
7166

7267
// Load data
7368
NSError *error;
7469
NSData *data = [NSData dataWithContentsOfURL:request.URL options:NSDataReadingMappedIfSafe error:&error];
7570
if (data) {
76-
[delegate URLRequest:strongOp didReceiveData:data];
71+
[delegate URLRequest:weakOp didReceiveData:data];
7772
}
78-
[delegate URLRequest:strongOp didCompleteWithError:error];
73+
[delegate URLRequest:weakOp didCompleteWithError:error];
7974
}];
8075

8176
weakOp = op;

packages/react-native/Libraries/Network/RCTFileRequestHandler.mm

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,14 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ
5353
_fileQueue.maxConcurrentOperationCount = 4;
5454
}
5555

56-
__weak NSBlockOperation *weakOp;
57-
NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{
58-
NSBlockOperation *strongOp = weakOp; // Strong reference to avoid deallocation during execution
59-
if (strongOp == nil || [strongOp isCancelled]) {
60-
return;
61-
}
62-
56+
__weak __block NSBlockOperation *weakOp;
57+
__block NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{
6358
// Get content length
6459
NSError *error = nil;
6560
NSFileManager *fileManager = [NSFileManager new];
6661
NSDictionary<NSString *, id> *fileAttributes = [fileManager attributesOfItemAtPath:request.URL.path error:&error];
6762
if (!fileAttributes) {
68-
[delegate URLRequest:strongOp didCompleteWithError:error];
63+
[delegate URLRequest:weakOp didCompleteWithError:error];
6964
return;
7065
}
7166

@@ -82,14 +77,14 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ
8277
expectedContentLength:[fileAttributes[NSFileSize] ?: @-1 integerValue]
8378
textEncodingName:nil];
8479

85-
[delegate URLRequest:strongOp didReceiveResponse:response];
80+
[delegate URLRequest:weakOp didReceiveResponse:response];
8681

8782
// Load data
8883
NSData *data = [NSData dataWithContentsOfURL:request.URL options:NSDataReadingMappedIfSafe error:&error];
8984
if (data) {
90-
[delegate URLRequest:strongOp didReceiveData:data];
85+
[delegate URLRequest:weakOp didReceiveData:data];
9186
}
92-
[delegate URLRequest:strongOp didCompleteWithError:error];
87+
[delegate URLRequest:weakOp didCompleteWithError:error];
9388
}];
9489

9590
weakOp = op;

0 commit comments

Comments
 (0)