Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executeAsyc relies on passed request data to be valid after returning? #19

Open
cen1 opened this issue Sep 22, 2020 · 0 comments
Open

Comments

@cen1
Copy link

cen1 commented Sep 22, 2020

Brief overview

First of all, apologies if I completely misunderstood this problem, the documentation and online samples are rather thin.

I am doing a fire-and-forget POST webhook call. I am calling the Postman echo server for testing. When request goes through, Postman reports content length 0 and null json in the response. Sometimes I also get a Poco::Exception occurred. [scheme=https, host=postman-echo.com] message=[Not a valid integer: 18446744073309551616] for content length header or a segfault. Due to this weird behaviour, I suspect that executeAsync tries to use some data that has already been deallocated once the method returns from scope.

If I add a sleep or pResponseCb->waitForCompletion(); before returning from method everything works as expected.

Code is almost line by line from async sample, except it is POST instead of GET.

void post(string body) {
   //init client and stuff...
    easyhttpcpp::MediaType::Ptr pMediaType(new easyhttpcpp::MediaType("application/json; charset=utf-8"));
    easyhttpcpp::RequestBody::Ptr pRequestBody = easyhttpcpp::RequestBody::create(pMediaType, body);

    easyhttpcpp::Request::Builder requestBuilder;

    easyhttpcpp::Request::Ptr pRequest = requestBuilder.setUrl("https://postman-echo.com/post")
        .httpPost(pRequestBody)
        .build();
    easyhttpcpp::Call::Ptr pCall = pHttpClient->newCall(pRequest);

    HttpClientCallback::Ptr pResponseCb = new HttpClientCallback();

    pCall->executeAsync(pResponseCb);
    //pResponseCb->waitForCompletion(); //this makes it work
}

Expected behavior

executeAsync should make a copy of all the data it needs before returning?

Actual behavior

executeAsync seems to rely on the passed data to be valid after returning.

Steps to reproduce

The code sample above should be enough.

Specifications like the version of the project, operating system, or hardware etc.

Windows 10, VS2019, conan package shared build v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant