Add a method to stop EM gracefully. #272

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

ab commented Oct 13, 2011

EventMachine_t::ScheduleHalt() currently will break out of the main event loop even if there is data that still remains to be written to sockets. The new method ScheduleGracefulHalt schedules a close of all open sockets and waits until they have closed to actually exit.

This behavior can be seen with a very simple server: https://gist.github.com/1283144

The server replies to each message the client sends, but the client never actually receives the message when stop is called instead of graceful_stop.

andy@zara:~$ nc localhost 8081
Hello!
hi  
Received 3 bytes
graceful_stop
Received 14 bytes
andy@zara:~$ 
andy@zara:~$ nc localhost 8081
Hello!
hi
Received 3 bytes
stop
andy@zara:~$ 
@ab ab Add a graceful_stop shutdown method.
EventMachine_t::ScheduleHalt currently will break out of the main event
loop even if there is data that still remains to be written to sockets.
The new method ScheduleGracefulHalt schedules a close of all open
sockets and waits until they have closed to actually exit.
6cb9322
Contributor

ibc commented Feb 22, 2012

This is a cool feature. Unfortunatelly ignored as 99% of pull requests in EventMachine.

ab commented Feb 27, 2012

Sigh. I'd be happy to have it in EventMachine-LE if you're interested. It hasn't been super thoroughly tested, but everything I've tried on it works well.

Contributor

ibc commented Feb 27, 2012

Hi, could you fork EventMachine-LE master branch nad make a pull request of your code? (maybe you need to adapt it a bit since we applied some other pull requests and there could be conflicts).

If you could include test units it would be more than great.

Contributor

ibc commented Feb 27, 2012

Hi again. I don't like the usage of fprintf function in the code, i.e:

fprintf(stderr, "warning: EventMachine hit max_shutdown_wait, killing %d sockets\n", GetConnectionCount());

That could be not desirable. For example in my case, my EM based server runs daemonized and logs to syslog.

ab commented Mar 1, 2012

I should have some time to do this over the weekend.

Contributor

ibc commented Mar 1, 2012

Thanks a lot.

sodabrew added this to the v1.2.0 milestone Feb 2, 2015

@sodabrew sodabrew modified the milestone: v1.2.0, v1.2.1 Feb 25, 2016

@sodabrew sodabrew modified the milestone: v1.3.0, v1.2.1 Apr 25, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment