unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* sigwinch and screen
       [not found] <CAOowiR0YXF6TAY2_Sv0KYfr0UL-VCAX=KX8OO_-DnOLG-hDbSA@mail.gmail.com>
@ 2011-09-14 14:29 ` Brian P O'Rourke
  2011-09-14 17:32   ` Eric Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Brian P O'Rourke @ 2011-09-14 14:29 UTC (permalink / raw)
  To: mongrel-unicorn

(my apologies if this gets posted twice - don't think my earlier mail
went through)

Hi,

I'm running unicorn within screen and have run into some trouble.
Unicorn tries to ignore sigwinch when it's not daemonized.
Unfortunately the check for daemonization fails when unicorn is exec'd
from a process that already has a pgrp.

You can simulate this problem from *within* a screen session with
something like this:

    screen sleep 5 && screen bundle exec unicorn -c unicorn.conf config.ru

sigwinch will be sent to the second screen session the first time you
change to it. This doesn't happen unless you launch at least two
screens in rapid succession, for reasons that escape me so far -
haven't dug into that part much yet.

It seems to me that this is a problem, and is occurring because
Unicorn's check for daemonization is "is init my parent or is my group
different from my pid?", which isn't necessarily the same as checking
whether daemonization has happened.

Here is the patch I would like to see applied:

diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index ae0e175..65880d4 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -282,7 +282,7 @@ class Unicorn::HttpServer
       when :USR2 # exec binary, stay alive in case something went wrong
         reexec
       when :WINCH
-        if Process.ppid == 1 || Process.getpgrp != $$
+        if Unicorn::Configurator::RACKUP[:daemonized]
           respawn = false
           logger.info "gracefully stopping all workers"
           kill_each_worker(:QUIT)
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: sigwinch and screen
  2011-09-14 14:29 ` sigwinch and screen Brian P O'Rourke
@ 2011-09-14 17:32   ` Eric Wong
  2011-09-15  0:44     ` Brian P O'Rourke
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Wong @ 2011-09-14 17:32 UTC (permalink / raw)
  To: unicorn list; +Cc: Brian P O'Rourke

Brian P O'Rourke <bpo@somnambulance.net> wrote:
> (my apologies if this gets posted twice - don't think my earlier mail
> went through)

I've noticed rubyforge has occasional slowness :<   It uses Postgrey so
first time posters could be delayed...

> I'm running unicorn within screen and have run into some trouble.
> Unicorn tries to ignore sigwinch when it's not daemonized.
> Unfortunately the check for daemonization fails when unicorn is exec'd
> from a process that already has a pgrp.
> 
> You can simulate this problem from *within* a screen session with
> something like this:
> 
>     screen sleep 5 && screen bundle exec unicorn -c unicorn.conf config.ru

So, start "screen", get a terminal + shell, /then/ type the above?

> sigwinch will be sent to the second screen session the first time you
> change to it. This doesn't happen unless you launch at least two
> screens in rapid succession, for reasons that escape me so far -
> haven't dug into that part much yet.

I haven't been able to reproduce it on my end.
It could be system-dependent (terminals are often wonky/inconsistent).

> It seems to me that this is a problem, and is occurring because
> Unicorn's check for daemonization is "is init my parent or is my group
> different from my pid?", which isn't necessarily the same as checking
> whether daemonization has happened.

Agreed.  Regardless of what the problem is, I like your check based on
RACKUP[:daemonized].  It's much more readable and obvious :)

> Here is the patch I would like to see applied:

I'll apply it.   Is there a commit message you'd like to use?
(Otherwise I'll just edit something based on your email)

Thanks!

> --- a/lib/unicorn/http_server.rb
> +++ b/lib/unicorn/http_server.rb
> @@ -282,7 +282,7 @@ class Unicorn::HttpServer
>        when :USR2 # exec binary, stay alive in case something went wrong
>          reexec
>        when :WINCH
> -        if Process.ppid == 1 || Process.getpgrp != $$
> +        if Unicorn::Configurator::RACKUP[:daemonized]
>            respawn = false
>            logger.info "gracefully stopping all workers"
>            kill_each_worker(:QUIT)
-- 
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sigwinch and screen
  2011-09-14 17:32   ` Eric Wong
@ 2011-09-15  0:44     ` Brian P O'Rourke
  2011-09-15  0:54       ` Eric Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Brian P O'Rourke @ 2011-09-15  0:44 UTC (permalink / raw)
  To: unicorn list

On Thu, Sep 15, 2011 at 1:32 AM, Eric Wong <normalperson@yhbt.net> wrote:
> Brian P O'Rourke <bpo@somnambulance.net> wrote:
>> You can simulate this problem from *within* a screen session with
>> something like this:
>>
>>     screen sleep 5 && screen bundle exec unicorn -c unicorn.conf config.ru
>
> So, start "screen", get a terminal + shell, /then/ type the above?
>

Correct. When running screen within screen like this, you just get a
new screen that executes the command. It happens consistently for me
on OSX when I launch several screens at once and the last active
screen is *not* unicorn - could certainly be system-dependent.

>> Here is the patch I would like to see applied:
>
> I'll apply it.   Is there a commit message you'd like to use?
> (Otherwise I'll just edit something based on your email)

You can just pull from my public fork here:
git://github.com/bpo/unicorn.git - branch name is
'daemonization_detection'

Cheers,
Brian P O'Rourke
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sigwinch and screen
  2011-09-15  0:44     ` Brian P O'Rourke
@ 2011-09-15  0:54       ` Eric Wong
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2011-09-15  0:54 UTC (permalink / raw)
  To: Brian P O'Rourke; +Cc: unicorn list

Brian P O'Rourke <bpo@somnambulance.net> wrote:
> You can just pull from my public fork here:
> git://github.com/bpo/unicorn.git - branch name is
> 'daemonization_detection'

Acked and pushed out as commit b48c6659b294b37f2c6ff3e75c1c9245522d48d1
Thanks!
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-15  1:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAOowiR0YXF6TAY2_Sv0KYfr0UL-VCAX=KX8OO_-DnOLG-hDbSA@mail.gmail.com>
2011-09-14 14:29 ` sigwinch and screen Brian P O'Rourke
2011-09-14 17:32   ` Eric Wong
2011-09-15  0:44     ` Brian P O'Rourke
2011-09-15  0:54       ` Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).