From adcd0eaaac76305402049c23528f36d30c8a7277 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Wed, 20 Jan 2016 17:36:25 +0200 Subject: [PATCH] [osx] Fix loop closing with pending requests The main loop will now wait for all the requests to complete before closing. This will make the FileSource on OSX block longer than it should at shutdown. --- platform/darwin/http_request_nsurl.mm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/platform/darwin/http_request_nsurl.mm b/platform/darwin/http_request_nsurl.mm index 306cf9629..9822c8097 100644 --- a/platform/darwin/http_request_nsurl.mm +++ b/platform/darwin/http_request_nsurl.mm @@ -5,6 +5,7 @@ #include #include #include +#include #import @@ -96,6 +97,11 @@ HTTPNSURLRequest::HTTPNSURLRequest(HTTPNSURLContext* context_, context(context_), existingResponse(existingResponse_), async([this] { handleResponse(); }) { + // Hold the main loop alive until the request returns. This + // is needed because completion handler runs in another + // thread and will notify this thread using AsyncTask. + util::RunLoop::Get()->ref(); + @autoreleasepool { NSURL* url = [NSURL URLWithString:@(url_.c_str())]; if (context->accountType == 0 && @@ -129,6 +135,7 @@ HTTPNSURLRequest::HTTPNSURLRequest(HTTPNSURLContext* context_, } HTTPNSURLRequest::~HTTPNSURLRequest() { + util::RunLoop::Get()->unref(); assert(!task); }