Skip to content

Request URL changes if I execute it in different thread #177

Description

@rbdm-qnt

In my program I need to do periodical get and post requests on different threads. At the beginning of my main I call RestClient::init(), then when I need to send a request I create it, I print it as:
std::cout << "Request url:\n" << request.url << "\n";

and then I assign it to my thread_pool to execute in another thread. The other thread calls execute() method in my Request struct:

[[nodiscard]] RestClient::Response execute() const {
switch (type) {
case get: { std::cout << " - Inside request.h get. URL:\n" << url << "\n"; return RestClient::get(url); }
default: { assert(false); }
}
}

The outputs from the first and second prints are as follows:
Request url in main thread:
https://api.bybit.com/private/linear/position/list

  • Pushed to threadpool
  • Inside request.h get. URL:
    t��t.com/private/linear/position/list

Of course, the request fails because of unkown url. I don't understand how is it possible that the assignment of the Request object to another thread could modify just the beginning of my url string. If I execute the same request in the main thread it works just fine, but I can't work with that in my program.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions