-
Notifications
You must be signed in to change notification settings - Fork 522
Shutting the server down causes a hang #9
Comments
Seems it's not OSX specific |
Just ran the sample on OS X (commit de6c32d) and it shut down cleanly when I hit enter. |
I've seen this too, it doesn't repro all the time. I believe it has something to do with the code that's closing all of the open libuv handles. |
Ah, yes after some more test runs I've gotten these 2 stack traces, but still no hangs for me.
|
I can consistently reproduce this by sending SIGINT (Ctrl+C in the terminal - which causes the terminal thread to freeze) and then hitting the port with another HTTP request. Command: |
I'm experiencing the exact same behaviour as reported by @natemcmaster. Ctrl+C results in a non responsive terminal, where as enter results in an immediate exit. After a few tries I got this different error which may be helpful:
|
This also manifests itself on linux. Solving this would allow me to move to kestrel from Nowin. |
Yeah, that's really irritating. |
is this libuv specific, as in it is handling ctrl-c and messing stuff up? |
Not really - it's in the hosting program.main... I think it's either a problem somewhere in how it's asking libuv to close connections before returning, or how it's getting ctrl-c notifications on different platforms. |
its a SIGINT on Linux/MAC OSX. I do not know what Windows reads it as |
I don't know how the coming CLR on POSIX will affect signal handling, but in the mean time one potential solution is to use Mono.Posix to handle SIGINT on Linux and OS X. The startup code would have to probe for OS type and maybe Runtime, but there are already places in aspnet 5 that have to do this. |
+1 for beta2 package of Kestrel on Ubuntu 14.0.4. Hitting Enter does not exist the server and seems to hag forever. Need to do Ctrl + C |
I have Console.WriteLine'd this down:
If you put a last Console.WriteLine at the end of ThreadStart, this gets executed. This means the thread's function runs to an end and the Join should return. I can only speculate about the reason, but given the exception, I would guess memory / stack corruption and you cannot trust the runtime anymore. |
- Added Stopping event to KestrelThread so that incoming connections get a chance to gracefully close before disposing the event loop - Call _post.Dispose instead of UnReference. Sometimes Dispose would happen on the finalizer thread and _queueCloseHandle would be null. #9
I send a PR for this, see #47. Can somebody test it out and let me know how it works out? It's working well for me. |
@davidfowl I can take a quick look |
- Added Stopping event to KestrelThread so that incoming connections get a chance to gracefully close before disposing the event loop - Call _post.Dispose instead of UnReference. Sometimes Dispose would happen on the finalizer thread and _queueCloseHandle would be null. #9
Sadly, I don't see a difference. My setup:
I have to revise my analysis a bit, though. The reason for the hang is that the KestrelThread's Stop rethrows the Exception and this bubbles up through all Dispose layers (Listener, KestrelEngine, ServerFactory, HostingEngine) until Hosting's Program.cs, where the ShutdownRequested's cancellation token event handler does not set the ManualResetEvent to actually unblock the program. |
I found the places where the memory gets overwritten: During loop_init I have stored the value of CreateMemory's GCHandle.Alloc in a local variable and compare that to what is used in DestroyMemory. Before loop_close, the value is 0, afterwards, it's -1 (since I compiled without NDEBUG). I meant to ask since the first time I looked at Kestrel: Why is the whole P/Invoke handling implemented so complicated? All libuv's loop needs is a pointer to a piece of memory that's large enough (loop_size()). Why not just save the IntPtr of AllocCoTaskMem of the proper size in a SafeHandle's handle and be done with it? |
@Tragetaschen I was testing my change on ubuntu and it still hung during shutdown. I think there was a change in libuv though since it works on windows and OSx with the bundled version. As for the pinvoke handling you can ask @loudej 😄 |
The Windows source code does not have the |
#60 fixes this |
I ran the sample on osx using k run and then hit enter to quit the app after making a single request, it hangs forever
The text was updated successfully, but these errors were encountered: