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

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

Open
rbdm-qnt opened this issue Feb 25, 2022 · 0 comments
Open

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

rbdm-qnt opened this issue Feb 25, 2022 · 0 comments

Comments

@rbdm-qnt
Copy link

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.

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