Restarter doesn't kill the right process #327

Closed
jspin opened this Issue Sep 8, 2012 · 7 comments

Projects

None yet

3 participants

@jspin

Hi, I just updated to v1.0003 and am still experiencing an issue similar to #223.

here's how I'm launching the app and what it reports afterward:

/usr/local/bin/plackup -s FCGI --port 8088 --host 127.0.0.1 -R lib -D bin/plack-responder.psgi &
FastCGI daemon started (pid 21614)

ps -ef | grep fcgi
ec2-user 21614 1 0 14:14 ? 00:00:00 perl-fcgi-pm
ec2-user 21615 21614 0 14:14 ? 00:00:00 perl-fcgi

( then when I update a module)

-- /web/live/lib/XXX/App/Main/List.pm updated.
Killing the existing server (pid:20722)
Successfully killed! Restarting the new server process.
bind/listen: Address already in use
-- /web/live/lib/XXX/App/Main/List.pm updated.
Killing the existing server (pid:21611)
Successfully killed! Restarting the new server process.
-- /web/live/lib/XXX/App/Main/List.pm updated.
-- /web/live/lib/XXX/App/Main/List.pm updated.
Killing the existing server (pid:20728)
Successfully killed! Restarting the new server process.
Killing the existing server (pid:20725)
Successfully killed! Restarting the new server process.
bind/listen: Address already in use
bind/listen: Address already in use
bind/listen: Address already in use

(which process id's are running now?)

ps -ef | grep fcgi
ec2-user 21614 1 0 14:14 ? 00:00:00 perl-fcgi-pm
ec2-user 21615 21614 0 14:14 ? 00:00:00 perl-fcgi

none of the pid's supplied in the "Killing the existing server" message are correct. as you can see, the original pids are still running.

another thing I noticed compared to v0.9985, although fairly minor, is that it tries 3x instead of 2 to kill/restart and the updated module is listed twice on the 2nd attempt.

unless I'm launching the app incorrectly, this appears to be a bug.

thanks for looking
-Joe

@miyagawa
plack member

Do you still see this issue? I think restarter isn't really compatible to forking managers like FCGI::ProcManager.

@ajmetz

Having this same issue right now, except it's in 2015.
>_<.

Plackup reports the correct pid after initialising...

[info] GXCatalystTest powered by Catalyst 5.90101
FastCGI daemon started (pid 4322)

...then kills the wrong pid when changes are detected:

-- /home/gamextra/public_html/GXCatalystTest/lib/GXCatalystTest/Controller/Root.pm updated.
Killing the existing server (pid:4321)
Successfully killed! Restarting the new server process.

...so that after restarting the server sort of fails:

[info] GXCatalystTest powered by Catalyst 5.90101
bind/listen: Address already in use

Is this a bug, or something I'm doing wrong? [Am new to using Plack].

@ajmetz

I fixed it by outputting the process id when I run the app,
i.e. using the plackup command with the --pid path/to/somefile.txt attribute, to save the pid somewhere. Then I edited Restarter.pm to read in the text file, and take its value as the pid to kill. I used File::Slurp and read_file to read in the text file with the pid in it. I left the existing $pid variable as it was, and saved the contents of the file to $realpid instead, and then edited the lines in the _kill_child subroutine to use the $realpid when it came to killing the process, instead of the $pid variable.
Obviously, this is tailoring the whole of Restarter.pm to my one specific web app scenario, so not the best of solutions. Yet it works for me, for now, so yay, =D.

@miyagawa
plack member

Don't use the -D (daemonize) option combined with Restarter.

@miyagawa
plack member

I tested without -D and it seems to work fine.

➜  Plack git:(master) plackup -s FCGI --port 8088 --host 127.0.0.1 -R lib eg/dot-psgi/Hello.psgi
Watching lib eg/dot-psgi/lib eg/dot-psgi/Hello.psgi for file updates.
FastCGI: manager (pid 28071): initialized
FastCGI: manager (pid 28071): server (pid 28072) started
FastCGI: server (pid 28072): initialized


-- /Users/miyagawa/dev/Plack/lib/Plack.pm updated.
Killing the existing server (pid:28071)
FastCGI: manager (pid 28071): received signal TERM
FastCGI: manager (pid 28071): sending TERM to PIDs, 28072
FastCGI: manager (pid 28071): server (pid 28072) exited with status 0
FastCGI: manager (pid 28071): dying: safe exit from signal TERM
Successfully killed! Restarting the new server process.
FastCGI: manager (pid 28096): initialized
FastCGI: manager (pid 28096): server (pid 28097) started
FastCGI: server (pid 28097): initialized
-- /Users/miyagawa/dev/Plack/lib/Plack.pm updated.
Killing the existing server (pid:28096)
FastCGI: manager (pid 28096): received signal TERM
FastCGI: manager (pid 28096): sending TERM to PIDs, 28097
FastCGI: manager (pid 28096): server (pid 28097) exited with status 0
FastCGI: manager (pid 28096): dying: safe exit from signal TERM
Successfully killed! Restarting the new server process.
FastCGI: manager (pid 28101): initialized
FastCGI: manager (pid 28101): server (pid 28102) started
FastCGI: server (pid 28102): initialized
@miyagawa miyagawa closed this Oct 23, 2015
@ajmetz

Just put Restarter.pm back as it originally was, and tried the commandline again, without -D

[~/public_html/GXCatalystTest]# plackup -s FCGI -r --listen www.game-extra.com:55900 --pid /home/gamextra/public_html/GXCatalystTest/pid.txt gxcatalysttest.psgi
Watching ./lib gxcatalysttest.psgi for file updates.
[debug] Debug messages enabled
[debug] Statistics enabled
[debug] Loaded Config "/home/gamextra/public_html/GXCatalystTest/gxcatalysttest.conf"
Term::Size::Any is not installed, can't autodetect terminal column width
Trouble trying to detect your terminal size, looking at $ENV{COLUMNS}
Cannot determine desired terminal width, using default of 80 columns
[debug] Loaded plugins:
.----------------------------------------------------------------------------.
| Catalyst::Plugin::ConfigLoader  0.34                                       |
'----------------------------------------------------------------------------'

[debug] Loaded PSGI Middleware:
.----------------------------------------------------------------------------.
| Catalyst::Middleware::Stash                                                |
| Plack::Middleware::HTTPExceptions                                          |
| Plack::Middleware::RemoveRedundantBody  0.04                               |
| Plack::Middleware::FixMissingBodyInRedirect  0.12                          |
| Plack::Middleware::ContentLength                                           |
| Plack::Middleware::MethodOverride  0.15                                    |
| Plack::Middleware::Head                                                    |
'----------------------------------------------------------------------------'

[debug] Loaded Request Data Handlers:
.----------------------------------------------------------------------------.
| application/x-www-form-urlencoded                                          |
| application/json                                                           |
'----------------------------------------------------------------------------'

[debug] Loaded dispatcher "Catalyst::Dispatcher"
[debug] Loaded engine "Catalyst::Engine"
[debug] Found home "/home/gamextra/public_html/GXCatalystTest"
[debug] Loaded components:
.-----------------------------------------------------------------+----------.
| Class                                                           | Type     |
+-----------------------------------------------------------------+----------+
| GXCatalystTest::Controller::Root                                | instance |
'-----------------------------------------------------------------+----------'

[debug] Loaded Private actions:
.----------------------+--------------------------------------+--------------.
| Private              | Class                                | Method       |
+----------------------+--------------------------------------+--------------+
| /default             | GXCatalystTest::Controller::Root     | default      |
| /index               | GXCatalystTest::Controller::Root     | index        |
| /login               | GXCatalystTest::Controller::Root     | login        |
| /end                 | GXCatalystTest::Controller::Root     | end          |
'----------------------+--------------------------------------+--------------'

[debug] Loaded Path actions:
.-------------------------------------+--------------------------------------.
| Path                                | Private                              |
+-------------------------------------+--------------------------------------+
| /                                   | /index                               |
| /...                                | /default                             |
| /login/                             | /login                               |
'-------------------------------------+--------------------------------------'

[info] GXCatalystTest powered by Catalyst 5.90101
FastCGI: manager (pid 31884): initialized
FastCGI: manager (pid 31884): server (pid 31885) started
FastCGI: server (pid 31885): initialized
FastCGI: manager (pid 31884): received signal TERM
FastCGI: manager (pid 31884): sending TERM to PIDs, 31885
FastCGI: manager (pid 31884): server (pid 31885) exited with status 0
FastCGI: manager (pid 31884): dying: safe exit from signal TERM
-- /home/gamextra/public_html/GXCatalystTest/lib/GXCatalystTest/Controller/Root.pm updated.
Killing the existing server (pid:31884)
Successfully killed! Restarting the new server process.
[debug] Debug messages enabled
[debug] Statistics enabled
[debug] Loaded Config "/home/gamextra/public_html/GXCatalystTest/gxcatalysttest.conf"
Term::Size::Any is not installed, can't autodetect terminal column width
Trouble trying to detect your terminal size, looking at $ENV{COLUMNS}
Cannot determine desired terminal width, using default of 80 columns
[debug] Loaded plugins:
.----------------------------------------------------------------------------.
| Catalyst::Plugin::ConfigLoader  0.34                                       |
'----------------------------------------------------------------------------'

[debug] Loaded PSGI Middleware:
.----------------------------------------------------------------------------.
| Catalyst::Middleware::Stash                                                |
| Plack::Middleware::HTTPExceptions                                          |
| Plack::Middleware::RemoveRedundantBody  0.04                               |
| Plack::Middleware::FixMissingBodyInRedirect  0.12                          |
| Plack::Middleware::ContentLength                                           |
| Plack::Middleware::MethodOverride  0.15                                    |
| Plack::Middleware::Head                                                    |
'----------------------------------------------------------------------------'

[debug] Loaded Request Data Handlers:
.----------------------------------------------------------------------------.
| application/x-www-form-urlencoded                                          |
| application/json                                                           |
'----------------------------------------------------------------------------'

[debug] Loaded dispatcher "Catalyst::Dispatcher"
[debug] Loaded engine "Catalyst::Engine"
[debug] Found home "/home/gamextra/public_html/GXCatalystTest"
[debug] Loaded components:
.-----------------------------------------------------------------+----------.
| Class                                                           | Type     |
+-----------------------------------------------------------------+----------+
| GXCatalystTest::Controller::Root                                | instance |
'-----------------------------------------------------------------+----------'

[debug] Loaded Private actions:
.----------------------+--------------------------------------+--------------.
| Private              | Class                                | Method       |
+----------------------+--------------------------------------+--------------+
| /default             | GXCatalystTest::Controller::Root     | default      |
| /index               | GXCatalystTest::Controller::Root     | index        |
| /end                 | GXCatalystTest::Controller::Root     | end          |
| /login               | GXCatalystTest::Controller::Root     | login        |
'----------------------+--------------------------------------+--------------'

[debug] Loaded Path actions:
.-------------------------------------+--------------------------------------.
| Path                                | Private                              |
+-------------------------------------+--------------------------------------+
| /                                   | /index                               |
| /...                                | /default                             |
| /login/                             | /login                               |
'-------------------------------------+--------------------------------------'

[info] GXCatalystTest powered by Catalyst 5.90101
bind/listen: Address already in use

...this ends up working in the browser - updates to files will be noticed, yet I assume is not a complete solution as the bind/listen error still appears at the end.

@ajmetz

Update! My bad! I had two terminal windows opened. Tried again with just one, and the bind/listen error has gone away, =D. Thank you! Will avoid -D in future. =).

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