joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 771 forks source link

[Quick fix] iOS Release network requests not completing #722

Closed teodorciuraru closed 2 years ago

teodorciuraru commented 3 years ago

Dependencies

"react": "16.13.1",
"react-native": "0.63.4",
"rn-fetch-blob": "^0.12.0"

Problem

Network task fails to complete in Release mode (iOS) and seem to be blocking here, where self.task becomes nil and [nil resume] is called.

...
self.task = [session dataTaskWithRequest:req];
[self.task resume]; // self.task = nil

Workaround

Avoiding self.task makes the network requests work again, so we suspect a problem around it.

// self.task = [session dataTaskWithRequest:req];
// [self.task resume];
[[session dataTaskWithRequest:req] resume];

Proposal Kindly select an option that works for both of us so a PR can be submitted:

  1. Avoid using the self.task property altogether. (probably not possible because it's used on cancelRequest)
  2. Should the task be declared weak? Declare self.task as strong.
  3. Postponing assignment:
    NSURLSessionDataTask *task = [session dataTaskWithRequest:req];
    [task resume];
    self.task = task;

Work will be started immediately after response, because this issue is critical to us.

Edit: Submitted option 3 as a PR, cause it looks the least intrusive and would really help.