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

Dangling threads when stopping SimpleHttpServer #67

Closed
CVertex opened this issue Dec 18, 2015 · 3 comments
Closed

Dangling threads when stopping SimpleHttpServer #67

CVertex opened this issue Dec 18, 2015 · 3 comments
Labels

Comments

@CVertex
Copy link
Contributor

CVertex commented Dec 18, 2015

Hi Spotify API people,

I'm automating the use of the Spotify API for collecting track data for our users. So we can collect data for several hours, we're using AuthorizationCodeAuth which supports token refreshing.

After collection, I noticed our exe doesn't terminate..

The problem is with the SimpleHttpServer.

Here's a simplified version of my collection process that highlights the problem..

// Play with http server
var s = new SimpleHttpServer(8000, AuthType.Authorization);
var httpThread = new Thread(s.Listen);
httpThread.Start();
C.WriteLine("HTTP Server started");
C.WriteLine("Sleeping for 30s...");
// NOTE: while sleeping, visit http://localhost:8000/?code=XXX&state=XSS in chrome

Thread.Sleep(30 * 1000);

C.WriteLine("Shutting down server");
s.Dispose();

After investigating, I noticed HttpProcessor.StreamReadLine is in an infinite loop. It is constantly reading nextChar of -1 forever and ever.

It appears to be chrome's request for favicon.ico, causing the StreamReadLine method to get stuck in an infinite loop.

After some googling, I noticed SimpleHttpServer is very similar to http://www.codeproject.com/Articles/137979/Simple-HTTP-Server-in-C

This is interesting, because someone reports a similar problem! http://www.codeproject.com/Messages/4951831/shutdown.aspx

So it looks like he's suggesting killing the HTTP processing thread.

Any ideas how we can do this?

I mean, it's easy enough to keep track of the thread, but what if they are multiple threads running concurrently, how do we keep track of open threads and abort them?

Or ideally, can we handle the favicon.ico problem?

Thanks

@JohnnyCrazy
Copy link
Owner

Hey @CVertex , thanks for the report.

Could you try calling httpThread.Abort() and see if it works? This will propably raise some type of exception, but I don't have any better approach right now.

@CVertex
Copy link
Contributor Author

CVertex commented Jan 4, 2016

Hey @JohnnyCrazy. Thanks for the idea. I tried it out and it doesn't work. That's because the HTTPProcessor is failing, and it has it's own thread.

@JohnnyCrazy
Copy link
Owner

Should be fixed by #91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants