镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Open

Description

@cen1

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions