Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Fix crash of iOS FlipperNetworkPlugin #563

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ + (void)injectIntoNSURLSessionTaskResume
Method originalResume = class_getInstanceMethod(className, selector);

void (^swizzleBlock)(NSURLSessionTask *) = ^(NSURLSessionTask *slf) {

// iOS's internal HTTP parser finalization code is mysteriously not thread safe,
// invoke it asynchronously has a chance to cause a `double free` crash.
// This line below will ask for HTTPBody synchronously, make the HTTPParser parse the request and cache them in advance,
// After that the HTTPParser will be finalized,
// make sure other threads inspecting the request won't trigger a race to finalize the parser.
[slf.currentRequest HTTPBody];

[[FLEXNetworkObserver sharedObserver] URLSessionTaskWillResume:slf];
((void(*)(id, SEL))objc_msgSend)(slf, swizzledSelector);
};
Expand Down