Skip to content

Commit

Permalink
Fix a bug with gunicorn master process not shutting down.
Browse files Browse the repository at this point in the history
The problem was that we performed eventlet monkey patching inside master instead
of only inside workers which broke signal handling (master never received
signals so it never shut down).
  • Loading branch information
Kami committed Apr 20, 2016
1 parent 18210d8 commit 5677c8a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
12 changes: 12 additions & 0 deletions st2api/st2api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
# limitations under the License.

import os
import sys

import eventlet
import pecan
from oslo_config import cfg
from pecan.middleware.static import StaticFileMiddleware
Expand Down Expand Up @@ -52,6 +54,16 @@ def setup_app(config=None):

is_gunicorn = getattr(config, 'is_gunicorn', False)
if is_gunicorn:
# Note: We need to perform monkey patching in the worker. If we do it in
# the master process (gunicorn_config.py), it breaks tons of things
# including shutdown
eventlet.monkey_patch(
os=True,
select=True,
socket=True,
thread=False if '--use-debugger' in sys.argv else True,
time=True)

st2api_config.register_opts()
# This should be called in gunicorn case because we only want
# workers to connect to db, rabbbitmq etc. In standalone HTTP
Expand Down
10 changes: 0 additions & 10 deletions st2api/st2api/gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,11 @@
from __future__ import absolute_import

import os
import sys

import eventlet

__all__ = [
'app'
]

eventlet.monkey_patch(
os=True,
select=True,
socket=True,
thread=False if '--use-debugger' in sys.argv else True,
time=True)

bind = '127.0.0.1:9101'

config_args = ['--config-file', os.environ.get('ST2_CONFIG_PATH', '/etc/st2/st2.conf')]
Expand Down
13 changes: 13 additions & 0 deletions st2auth/st2auth/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import eventlet
import pecan
from oslo_config import cfg

Expand Down Expand Up @@ -44,6 +47,16 @@ def setup_app(config=None):

is_gunicorn = getattr(config, 'is_gunicorn', False)
if is_gunicorn:
# Note: We need to perform monkey patching in the worker. If we do it in
# the master process (gunicorn_config.py), it breaks tons of things
# including shutdown
eventlet.monkey_patch(
os=True,
select=True,
socket=True,
thread=False if '--use-debugger' in sys.argv else True,
time=True)

# This should be called in gunicorn case because we only want
# workers to connect to db, rabbbitmq etc. In standalone HTTP
# server case, this setup would have already occurred.
Expand Down
10 changes: 0 additions & 10 deletions st2auth/st2auth/gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,11 @@
from __future__ import absolute_import

import os
import sys

import eventlet

__all__ = [
'app'
]

eventlet.monkey_patch(
os=True,
select=True,
socket=True,
thread=False if '--use-debugger' in sys.argv else True,
time=True)

bind = '127.0.0.1:9100'

config_args = ['--config-file', os.environ.get('ST2_CONFIG_PATH', '/etc/st2/st2.conf')]
Expand Down
9 changes: 9 additions & 0 deletions st2stream/st2stream/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"""

import os
import sys

import eventlet
import pecan
from oslo_config import cfg

Expand Down Expand Up @@ -56,6 +58,13 @@ def setup_app(config=None):

is_gunicorn = getattr(config, 'is_gunicorn', False)
if is_gunicorn:
eventlet.monkey_patch(
os=True,
select=True,
socket=True,
thread=False if '--use-debugger' in sys.argv else True,
time=True)

st2stream_config.register_opts()
# This should be called in gunicorn case because we only want
# workers to connect to db, rabbbitmq etc. In standalone HTTP
Expand Down
10 changes: 0 additions & 10 deletions st2stream/st2stream/gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,11 @@
from __future__ import absolute_import

import os
import sys

import eventlet

__all__ = [
'app'
]

eventlet.monkey_patch(
os=True,
select=True,
socket=True,
thread=False if '--use-debugger' in sys.argv else True,
time=True)

bind = '127.0.0.1:9101'

config_args = ['--config-file', os.environ.get('ST2_CONFIG_PATH', '/etc/st2/st2.conf')]
Expand Down

0 comments on commit 5677c8a

Please sign in to comment.