Skip to content

Commit 2fdf1f7

Browse files
committed
Worker accidentally sets a default socket timeout, but should only be active for shutdown
1 parent 697fadc commit 2fdf1f7

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

celery/bootsteps.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from .five import values, with_metaclass
1919
from .utils.imports import instantiate, qualname
2020
from .utils.log import get_logger
21-
from .utils.threads import default_socket_timeout
2221

2322
try:
2423
from greenlet import GreenletExit
@@ -28,9 +27,6 @@
2827

2928
__all__ = ['Blueprint', 'Step', 'StartStopStep', 'ConsumerStep']
3029

31-
#: Default socket timeout at shutdown.
32-
SHUTDOWN_SOCKET_TIMEOUT = 5.0
33-
3430
#: States
3531
RUN = 0x1
3632
CLOSE = 0x2
@@ -149,22 +145,21 @@ def send_all(self, parent, method,
149145
description=None, reverse=True, propagate=True, args=()):
150146
description = description or method.capitalize()
151147
steps = reversed(parent.steps) if reverse else parent.steps
152-
with default_socket_timeout(SHUTDOWN_SOCKET_TIMEOUT): # Issue 975
153-
for step in steps:
154-
if step:
155-
self._debug('%s %s...',
156-
description.capitalize(), step.alias)
157-
fun = getattr(step, method, None)
158-
if fun:
159-
try:
160-
fun(parent, *args)
161-
except Exception as exc:
162-
if propagate:
163-
raise
164-
logger.error(
165-
'Error while %s %s: %r',
166-
description, step.alias, exc, exc_info=1,
167-
)
148+
for step in steps:
149+
if step:
150+
self._debug('%s %s...',
151+
description.capitalize(), step.alias)
152+
fun = getattr(step, method, None)
153+
if fun:
154+
try:
155+
fun(parent, *args)
156+
except Exception as exc:
157+
if propagate:
158+
raise
159+
logger.error(
160+
'Error while %s %s: %r',
161+
description, step.alias, exc, exc_info=1,
162+
)
168163

169164
def stop(self, parent, close=True, terminate=False):
170165
what = 'terminating' if terminate else 'stopping'

celery/worker/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@
3636
from celery.utils import nodename, nodesplit, worker_direct
3737
from celery.utils.imports import reload_from_cwd
3838
from celery.utils.log import mlevel, worker_logger as logger
39+
from celery.utils.threads import default_socket_timeout
3940

4041
from . import state
4142

4243
__all__ = ['WorkController', 'default_nodename']
4344

45+
#: Default socket timeout at shutdown.
46+
SHUTDOWN_SOCKET_TIMEOUT = 5.0
47+
4448
SELECT_UNKNOWN_QUEUE = """\
4549
Trying to select queue subset of {0!r}, but queue {1} is not
4650
defined in the CELERY_QUEUES setting.
@@ -261,8 +265,9 @@ def _shutdown(self, warm=True):
261265
# if blueprint does not exist it means that we had an
262266
# error before the bootsteps could be initialized.
263267
if self.blueprint is not None:
264-
self.blueprint.stop(self, terminate=not warm)
265-
self.blueprint.join()
268+
with default_socket_timeout(SHUTDOWN_SOCKET_TIMEOUT): # Issue 975
269+
self.blueprint.stop(self, terminate=not warm)
270+
self.blueprint.join()
266271

267272
def reload(self, modules=None, reload=False, reloader=None):
268273
modules = self.app.loader.task_modules if modules is None else modules

0 commit comments

Comments
 (0)