Skip to content

Comments

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

Closed
smibe wants to merge 3 commits intogetsentry:masterfrom
smibe:fix/thread-hang-on-windows
Closed

Use WinHttpCloseHandle from another thread to cancel the http request.#568
smibe wants to merge 3 commits intogetsentry:masterfrom
smibe:fix/thread-hang-on-windows

Conversation

@smibe
Copy link

@smibe smibe commented Jun 30, 2021

No description provided.

Copy link
Contributor

@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?

Comment on lines 125 to 126
WinHttpCloseHandle(state->request);
state->request = 0;
Copy link
Contributor

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.

state->request = NULL;
}

return sentry__bgworker_shutdown(bgworker, timeout);
Copy link
Contributor

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