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

Use WinHttpCloseHandle from another thread to cancel the http request. #568

Closed
wants to merge 3 commits into from
Closed

Use WinHttpCloseHandle from another thread to cancel the http request. #568

wants to merge 3 commits into from

Conversation

smibe
Copy link

@smibe smibe commented Jun 30, 2021

No description provided.

Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!
Since you mention a shutdown hang, will closing the handle from the main thread just lead to an error on the background thread?

src/transports/sentry_transport_winhttp.c Outdated Show resolved Hide resolved
Comment on lines 125 to 126
WinHttpCloseHandle(state->request);
state->request = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question: Shouldn’t these be closed in a particular order, in this case request first? Also, while it does not really make a difference, why is this reset to 0 while the others use NULL?

Also, since this can race with the background thread, might it be a good idea to exchange state->request first before closing it? So the racing background thread does not try to double-close it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the order is important. Closing the session first will cancel all other requests in the queue as well.
When the request handle is closed, the background blocking function is unblocked and the loop continues. But because of no session handle all WinHttp requests will fail and the queue will get cleaned up.
This is not a nice solution, but still the best I could com up with.

WinHttpCloseHandle(state->request);
state->request = NULL;
}

return sentry__bgworker_shutdown(bgworker, timeout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation why the ordering is important. It might be a good idea to put that as a comment in the code.

I also saw that all the tests are failing, I think in that case also the ordering is important.
The main thread will ask the background thread to shut down here according to the timeout. I think you have to move all your close calls after this call here, because you do want to wait for the given timeout, instead of just throwing away all the requests that are currently in flight.

@smibe smibe closed this Jul 6, 2021
@smibe smibe deleted the fix/thread-hang-on-windows branch July 6, 2021 10:12
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

Successfully merging this pull request may close these issues.

3 participants