runtime errors iOS - pplxtasks.h

Dec 23, 2014 at 6:13 PM
after running through the documentation to build for iOS, I am running into a SIGTRAP runtime issue while trying to run just a basic http request.
    web::http::client::http_client client(U("https://<my-domain-name>.com"));
    
    // Create the fields to be inserted into the request
    std::vector<std::pair<std::string, web::json::value>> fields;
    fields.emplace_back(U("username"), web::json::value::value(username));
    fields.emplace_back(U("password"), web::json::value::value(password));
    
    web::json::value obj = web::json::value::object(fields, true);
    
    client.request(web::http::methods::GET, U("/oauth/token"), obj).then([&](pplx::task<web::http::http_response> task) {
        
            web::http::http_response response = task.get();
            web::json::value responseJSON = response.extract_json().get();
        
    });
The issue occurs in the then() function when I call the task.get() function to get the http_response. Stepping through the task.get() code I found that it is failing specifically at
_M_Impl->Wait()
The last line of my call stack is here:
virtual ~_PPLTaskHandle() 
{
    // Here is the sink of all task completion code paths
    _M_pTask->_M_taskEventLogger._LogTaskCompleted();
}
Any suggestions? I am building using MBP 10.10.1 and targeting iOS 8.1
Coordinator
Dec 23, 2014 at 11:13 PM
Hi cbreed28,

I recommend starting with the simplest example http request possible. How about something like a GET request to www.google.com? Does something like the following run successfully for you? Please note in the following code I'm blocking and waiting for the request to be completed and not asynchronously waiting. Here is some good information on programming with tasks if you are unfamiliar.
try
{
    http_client c("http://www.google.com");
    http_response response = c.request(methods::GET).get();
    if(response.status_code() == status_codes::OK)
    {
        // Get response body as a string
        std::string str = response.extract_string();
    }
    else
    {
        // Unexpected HTTP status code...
    }
} catch(const http_exception &e)
{
    // Network error occurred during request....
}
Does something like this work for you?

Steve
Dec 25, 2014 at 6:27 PM
Hi Steve,

Surprisingly, yes. calling .get() on the task returned by ::request() does work.

Also, using the .then() overload with the http_response object directly seems to be working as well.

I am curious why calling .get() on the task returned by ::request() method works where as calling .get() on the task<http_response> passed into the .then() function does not?

Thanks for the response,

Cory
Coordinator
Dec 28, 2014 at 12:01 AM
Hi Cory,

Are you aware that calls to task::get() and task::wait() will throw an exception if the task threw an exception or was canceled? And obviously if the exception goes unhandled it will break down the process. If you have a standalone repro that I can try and run I could take a look and investigate.

Thanks,
Steve