Skip to content

curl handle stashed to TLS hangs shutdown on various windows versions #223

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

Open
mitsuhiko opened this issue Aug 13, 2018 · 3 comments
Open

Comments

@mitsuhiko
Copy link
Contributor

We have not fully identified what the cause it but it would appear that if a curl easy handle is put to TLS on windows, it can cause hangs on shutdown on certain versions. I'm entirely unsure what causes this and the exact conditions of the hang are very mysterious.

What we know so far is that if the handle is made and put to TLS everything is fine. If the handle however did an HTTP request first, is kept in TLS the program will hang on shutdown the first time after the HTTP request is made but if the program is run a second time it succeeds and only will start blocking again after some time has passed (6 hours?). Even a computer restart does not bring the program back to hanging. We saw this with Windows 7, Windows Server 2012.

This sounds very much like something in curl itself but it's mysterious nontheless. We currently work around by resetting the handles before shutdown on all threads that have one.

@alexcrichton
Copy link
Owner

Oh dear, this definitely sounds bad! I agree that this is probably a curl issue, but I can at least chime in and say that I've definitely seen my fair share of weirdness of TLS destructors and windows. At least in the standard library we have to update tests to avoid that in the past because it causes various hangs and crashes.

I've also never managed to bottom out the issues here, I've sort of just prayed all along that it's not a bug in libstd (or in this case libcurl) and it's instead just a weird Windows issue.

In any case I definitely agree that manually resetting TLS vars is the best way to go here, that'll make sure that hopefully no code executes on a TLS destructor

@mitsuhiko
Copy link
Contributor Author

@alexcrichton any pointers to those hangs? I have not had much success in finding similar cases and the fact that tls on windows can cause hangs is concerning.

@alexcrichton
Copy link
Owner

I think what I was remembering were cases like rust-lang/rust#20704 where if a thread is panicking while the main thread exits on windows "weird stuff happens" including either segfaults or deadlock. These were all really long ago though and we may have just fixed bugs in libstd, I certainly haven't seen anything recently

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

2 participants