celery workers randomly hang on IPC (causing all jobs to queue, but no longer run)
Fails in the same way on multiple celery versions: celery version 3.1.7 billiard version 3.3.0.23 celery version 3.1.25 billiard version 3.3.0.23
celery worker -l debug --autoscale=50,4 -Ofair -Q tower_scheduler,tower_broadcast_all,tower,localhost -n celery@localhost
Steps to reproduce
Happens sporadically when running our nightly 8 hour integration tests on Ubuntu 14.04 and 16.04. Does not happen on RHEL 7 nor Centos 7. We are working on a set of smaller recreation steps.
Expected behavior
- For the workers to continue processing work.
Actual behavior
The celery master process and a particular worker both block on the same file descriptor, performing a read(). The worker has finished a job and is ready for more work. The parent is "locked up", blocking on the read() system call shared by the worker.
Restarting celery "fixes" the issue. More surgically, sending a SIGUSR1 to the master process "fixes" the issue by breaking it out of the read() system call. The child then returns from the read and seems to process a/the pending message. The master process does NOT try to read() from the PIPE again.
- Master process strace right before the SIGUSR1 https://gist.github.com/ryanpetrello/3d2ee5556ac5d9bb778a46e5165c3f14
- Worker process strace right before the SIGUSR1 https://gist.github.com/ryanpetrello/442e31102a4671a95b4ef2ef41d27bf1
- lsof before the SIGUSR1 https://gist.github.com/chrismeyersfsu/17c87a314e8fe8931c9994d8fd7ca95e
https://github.com/celery/celery/blob/3.1/celery/concurrency/asynpool.py#L220 is where we are hanging. This is a call to __read__ gotten from https://github.com/celery/billiard/blob/3.3/Modules/_billiard/multiprocessing.c#L202
This is non-blocking and non-asynchronous. I don't really understand how this code isn't susceptible to a deadlock/infinite blocking scenario. The read is non-blocking and is called in such a way that it can block forever if the child dies.
We are now trying to recreate the problem with CELERY_RDBSIG="1" set so that we can jump into a remote debug session when the deadlock occurs.
Any advise would be helpful.
From an OS perspective, I can't reason how this could occur.
- No
write()being observed after the SIGUSR1. - 2 processes blocked on the same PIPE via a read(). This means that there is either no data in the pipe or not enough data.
- One process "gives up" (because we sent the SIGUSR1)
- Then the other processes read() proceeds with data ... without a write() observed.
I have the same issue here, workers look like running but they aren't processing messages.

I'm running on Python 3.6 and using Celery 4.1.0
@codeadict are you able to strace the two processes (worker and parent) to see if they are both stuck on the same file descriptor?
You can verify it's the same fd with sudo lsof | grep 53r where 53r is the number of the file descriptor the processes are blocked on.
@codeadict as @chrismeyersfsu mentioned, you can strace the master celery process and see if it's stuck reading on a pipe:
$ sudo strace -p <pid-of-celery-master-process> -s 100
Process X attached
read(53
If you have python-dbg installed w/ Python symbols, you can also use gdb to see where the master is stuck:
$ gdb python -p <pid-of-master-process>
...
(gdb) py-list
216 # header
217
218 while Hr < 4:
219 try:
220 n = __read__(
>221 fd, bufv[Hr:] if readcanbuf else bufv, 4 - Hr,
https://github.com/celery/celery/blob/v3.1.17/celery/concurrency/asynpool.py#L219
Same problem.
celery==3.1.23, billiard==3.3.0.23
Workers started with options: -time-limit=7200 --autoscale=64,2 --maxtasksperchild=1
python 2.7.3
After few hours celery 'freeze' I see that master and childs infinity wait read() on pipes (b.t.w, different pipes).
So, this is master process:
root@vm1:~# strace -p 41840
Process 41840 attached - interrupt to quit
read(50, ^C <unfinished ...>
Process 41840 detached
root@vm1:~# sudo lsof | grep 50r
python 41840 root 50r FIFO 0,8 0t0 548796 pipe
python 46237 root 50r CHR 1,3 0t0 7604 /dev/null
python 46304 root 50r FIFO 0,8 0t0 548796 pipe
root@vm1:~# ls -lh /proc/41840/fd/50
lr-x------ 1 root root 64 Oct 20 10:02 /proc/41840/fd/50 -> pipe:[548796]
root@vm1:~# (find /proc -type l | xargs ls -l | fgrep 'pipe:[548796]') 2>/dev/null
lr-x------ 1 root root 64 Oct 20 10:02 /proc/41840/fd/50 -> pipe:[548796]
lr-x------ 1 root root 64 Oct 20 10:02 /proc/41840/fd/51 -> pipe:[548796]
lr-x------ 1 root root 64 Oct 20 10:07 /proc/41840/task/41840/fd/50 -> pipe:[548796]
lr-x------ 1 root root 64 Oct 20 10:07 /proc/41840/task/41840/fd/51 -> pipe:[548796]
l-wx------ 1 root root 64 Oct 20 10:02 /proc/46237/fd/51 -> pipe:[548796]
l-wx------ 1 root root 64 Oct 20 10:07 /proc/46237/task/46237/fd/51 -> pipe:[548796]
lr-x------ 1 root root 64 Oct 20 10:02 /proc/46304/fd/50 -> pipe:[548796]
lr-x------ 1 root root 64 Oct 20 10:02 /proc/46304/fd/51 -> pipe:[548796]
lr-x------ 1 root root 64 Oct 20 10:07 /proc/46304/task/46304/fd/50 -> pipe:[548796]
lr-x------ 1 root root 64 Oct 20 10:07 /proc/46304/task/46304/fd/51 -> pipe:[548796]
And one of childs:
root@vm1:~# strace -p 46304
Process 46304 attached - interrupt to quit
read(16, ^C <unfinished ...>
Process 46304 detached
root@vm1:~# ls -lh /proc/46304/fd/16
lr-x------ 1 root root 64 Oct 20 10:02 /proc/46304/fd/16 -> pipe:[482281]
root@vm1:~# (find /proc -type l | xargs ls -l | fgrep 'pipe:[482281]') 2>/dev/null
lr-x------ 1 root root 64 Oct 20 10:02 /proc/41840/fd/16 -> pipe:[482281]
l-wx------ 1 root root 64 Oct 20 10:02 /proc/41840/fd/17 -> pipe:[482281]
lr-x------ 1 root root 64 Oct 20 10:07 /proc/41840/task/41840/fd/16 -> pipe:[482281]
l-wx------ 1 root root 64 Oct 20 10:07 /proc/41840/task/41840/fd/17 -> pipe:[482281]
lr-x------ 1 root root 64 Oct 20 10:02 /proc/46237/fd/16 -> pipe:[482281]
l-wx------ 1 root root 64 Oct 20 10:02 /proc/46237/fd/17 -> pipe:[482281]
lr-x------ 1 root root 64 Oct 20 10:07 /proc/46237/task/46237/fd/16 -> pipe:[482281]
l-wx------ 1 root root 64 Oct 20 10:07 /proc/46237/task/46237/fd/17 -> pipe:[482281]
lr-x------ 1 root root 64 Oct 20 10:02 /proc/46304/fd/16 -> pipe:[482281]
lr-x------ 1 root root 64 Oct 20 10:07 /proc/46304/task/46304/fd/16 -> pipe:[482281]
root@vm1:~#
And this current 'freezed' frame in master process:
Thread 0x7efc1c101700
('Frame: ', 63347776)
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/opt/waf/python/lib/python2.7/site-packages/celery/__main__.py", line 54, in <module>
main()
File "/opt/waf/python/lib/python2.7/site-packages/celery/__main__.py", line 30, in main
main()
File "/opt/waf/python/lib/python2.7/site-packages/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/opt/waf/python/lib/python2.7/site-packages/celery/bin/celery.py", line 793, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/opt/waf/python/lib/python2.7/site-packages/celery/bin/base.py", line 311, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/opt/waf/python/lib/python2.7/site-packages/celery/bin/celery.py", line 785, in handle_argv
return self.execute(command, argv)
File "/opt/waf/python/lib/python2.7/site-packages/celery/bin/celery.py", line 717, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/opt/waf/python/lib/python2.7/site-packages/celery/bin/worker.py", line 179, in run_from_argv
return self(*args, **options)
File "/opt/waf/python/lib/python2.7/site-packages/celery/bin/base.py", line 274, in __call__
ret = self.run(*args, **kwargs)
File "/opt/waf/python/lib/python2.7/site-packages/celery/bin/worker.py", line 212, in run
state_db=self.node_format(state_db, hostname), **kwargs
File "/opt/waf/python/lib/python2.7/site-packages/celery/worker/__init__.py", line 206, in start
self.blueprint.start(self)
File "/opt/waf/python/lib/python2.7/site-packages/celery/bootsteps.py", line 123, in start
step.start(parent)
File "/opt/waf/python/lib/python2.7/site-packages/celery/bootsteps.py", line 374, in start
return self.obj.start()
File "/opt/waf/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 279, in start
blueprint.start(self)
File "/opt/waf/python/lib/python2.7/site-packages/celery/bootsteps.py", line 123, in start
step.start(parent)
File "/opt/waf/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 838, in start
c.loop(*c.loop_args())
File "/opt/waf/python/lib/python2.7/site-packages/celery/worker/loops.py", line 76, in asynloop
next(loop)
File "/opt/waf/python/lib/python2.7/site-packages/kombu/async/hub.py", line 340, in create_loop
cb(*cbargs)
File "/opt/waf/python/lib/python2.7/site-packages/celery/concurrency/asynpool.py", line 279, in on_result_readable
next(it)
File "/opt/waf/python/lib/python2.7/site-packages/celery/concurrency/asynpool.py", line 221, in _recv_message
fd, bufv[Hr:] if readcanbuf else bufv, 4 - Hr,
()
@harlov @codeadict @chrismeyersfsu Did you find any solution or workaround?
No. We are upgrading to celery 4. Will run out same set of tests that invokes this error and see if we can recreate on celery 4.
@korycins we remove --autoscale and --maxtasksperchild - all okay yet.
I gues ongoing respawning workers with autoscale о maxtasksperchild may cause this situation.
@chrismeyersfsu I have the same issue with celery 4.1 so I guess switching to v4.1 will not help you. Previously I used only --autoscale option. Workers hang on from time to time ( around once per week) but when I added maxtasksperchild=20, workers hang on around once per hour. I thought that problem can be with maxtasksperchild so I removed it. I created custom autoscale to dynamically scale up/down based on free resources and the same issue occurs so I guess problem is connected with re spawning workers (as @harlov said)
can anyone verify the issues on top of latest master? not sure if it's already fixed with latest commit.
@auvipy which commit(s) do you suspect might resolve this? I'm currently able to reproduce this issue on celery 4.1.0, billiard 3.5.0.3 from PyPI.
I am not sure so could you plz try the master branch? If after releasing 4.2 it still exists work would be carried out to fix
@auvipy we could give it a try, but it may be hard to say for sure - personally, we only seem to encounter this hang once every few weeks, so it's pretty hard to narrow down.
@ryanpetrello Try to add max_task_per_child and set it to 1. http://docs.celeryproject.org/en/latest/userguide/workers.html#max-tasks-per-child-setting This should increase posibility of issue occurrence
Same issue, cannot reproduce right now, I thought It was configure issue, when restart just un-hang the worker, but looks like it happening from time to time.
Just chiming in to say we also run into this issue. celery 4.1.0, kombu 4.1.0, billiard 3.5.0.3.
Command line: /usr/bin/python /usr/local/bin/celery worker --app myapp.celery -B --loglevel INFO --autoscale=5,1 --max-tasks-per-child=50 --max-memory-per-child=1000000 -O fair
With respect to blocking on file descriptors, we see the same as @harlov above: the master is in a deadlock with one of its workers.
Sending SIGUSR1 to the celery master "unsticks" the process and dumps the stacktrace below. What is suspicious is that in a function "on_result_readable" it gets stuck on a read. This feels like a classic race condition: poll() returns readable but the read() blocks. This can happen, this is why it is always recommended to set the FDs in non-block mode to make sure nothing goes wrong.
Relevant message on LKML: https://lkml.org/lkml/2011/6/18/105
Not sure it is easy to set the descriptors non-blocking, because we have an environment with many celery masters and there's always a few stuck, if it's a simple change we may be able to test it quickly.
MainThread [636/660]
=================================================
File "/usr/local/bin/celery", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 14, in main
_main()
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 326, in main
cmd.execute_from_commandline(argv)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 488, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 281, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 480, in handle_argv
return self.execute(command, argv)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 412, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/usr/local/lib/python2.7/dist-packages/celery/bin/worker.py", line 221, in run_from_argv
return self(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 244, in __call__
ret = self.run(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/worker.py", line 256, in run
worker.start()
File "/usr/local/lib/python2.7/dist-packages/celery/worker/worker.py", line 203, in start
self.blueprint.start(self)
File "/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py", line 119, in start
step.start(parent)
File "/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py", line 370, in start
return self.obj.start()
File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer/consumer.py", line 320, in start
blueprint.start(self)
File "/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py", line 119, in start
step.start(parent)
File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer/consumer.py", line 596, in start
c.loop(*c.loop_args())
File "/usr/local/lib/python2.7/dist-packages/celery/worker/loops.py", line 88, in asynloop
next(loop)
File "/usr/local/lib/python2.7/dist-packages/kombu/async/hub.py", line 354, in create_loop
cb(*cbargs)
File "/usr/local/lib/python2.7/dist-packages/celery/concurrency/asynpool.py", line 292, in on_result_readable
next(it)
File "/usr/local/lib/python2.7/dist-packages/celery/concurrency/asynpool.py", line 235, in _recv_message
fd, bufv[Hr:] if readcanbuf else bufv, 4 - Hr,
File "/usr/local/lib/python2.7/dist-packages/celery/apps/worker.py", line 349, in cry_handler
safe_say(cry())
File "/usr/local/lib/python2.7/dist-packages/celery/utils/debug.py", line 193, in cry
traceback.print_stack(frame, file=out)
=================================================
LOCAL VARIABLES
=================================================
{'P': <functools.partial object at 0x7f29da0f1c58>,
'frame': <frame object at 0x37137b0>,
'out': <vine.five.WhateverIO object at 0x7f29da14e150>,
'sep': u'=================================================',
'sepchr': u'=',
'seplen': 49,
'thread': <_MainThread(MainThread, started 139818014390016)>,
'threading': <module 'threading' from '/usr/lib/python2.7/threading.pyc'>,
'tid': 139818014390016,
'tmap': {139818014390016: <_MainThread(MainThread, started 139818014390016)>}}
Just an update. We spent some time testing things and trying to reproduce it.
- Setting max_tasks_per_child to 1 makes it worse
- Removing -O fair makes no difference
- Removing the autoscale also doesn't help
- We've so far only reproduced it on machines with kernel 4.9 (Stretch), not on machines with 3.16 (Jessie)
I verified that the file descriptors normally used by celery are all correctly marked non-blocking and they are. So the question is, how does the code block if it's every descriptor is non-blocking.
The track I'm following now is that the epoll() object is getting confused about the descriptors it's supposed to be watching. If you strace celery you get lots of output like:
14659 14:32:56.665937 epoll_ctl(4, EPOLL_CTL_ADD, 43, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=43, u64=14879199376994992171}}) = -1 EEXIST (File exists)
14659 14:32:56.667084 epoll_ctl(4, EPOLL_CTL_ADD, 16, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=16, u64=14879199376994992144}}) = -1 EEXIST (File exists)
14659 14:32:56.667278 epoll_ctl(4, EPOLL_CTL_ADD, 26, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=26, u64=14879199376994992154}}) = -1 EEXIST (File exists)
14659 14:32:56.667440 epoll_ctl(4, EPOLL_CTL_ADD, 23, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=23, u64=14879199376994992151}}) = -1 EEXIST (File exists)
14659 14:32:56.667607 epoll_ctl(4, EPOLL_CTL_DEL, 37, 0x7ffd31c17f60) = -1 ENOENT (No such file or directory)
14659 14:32:56.667804 epoll_ctl(4, EPOLL_CTL_DEL, 38, 0x7ffd31c17f60) = -1 ENOENT (No such file or directory)
It's entirely plausible that at some point a file descriptor that once was used for one thing gets used for something else, the hub gets confused and calls the wrong method and boom!
Ok, so I've found the problem, and I have strace output capturing it failing. And it's very subtle and to do with the following completely non-obvious 'feature' of the epoll() interface. From the manpage:
Q6 Will closing a file descriptor cause it to be removed from all epoll sets automatically? A6 Yes, but be aware of the following point. A file descriptor is a reference to an open file description (see open(2)). Whenever a file descriptor is duplicated via dup(2), dup2(2), fcntl(2) F_DUPFD, or fork(2), a new file descriptor referring to the same open file description is created. An open file description con‐ tinues to exist until all file descriptors referring to it have been closed. A file descriptor is removed from an epoll set only after all the file descriptors referring to the underlying open file description have been closed (or before if the file descrip‐ tor is explicitly removed using epoll_ctl(2) EPOLL_CTL_DEL). This means that even after a file descriptor that is part of an epoll set has been closed, events may be reported for that file descriptor if other file descriptors referring to the same under‐ lying file description remain open.
What is happening is that a file descriptor is being used by celery for communication, the file descriptor leaks to a worker, the master closes the file descriptor and then opens another for the sentinel which is not marked non-blocking. The child process dies causing the file descriptor to get marked as readable, the master tries to read it an blocks.
Yes, epoll() returns readability for a file descriptor that is no longer open in this process.
Here I'm pasting captured strace output for just fd 49 as evidence (apologies for the multi-line output, strace was monitoring multiple processes):
7417 15:04:00.001511 pipe( <unfinished ...>
7417 15:04:00.001646 <... pipe resumed> [49, 50]) = 0
7417 15:04:00.001727 fcntl(49, F_GETFL <unfinished ...>
7417 15:04:00.002091 <... fcntl resumed> ) = 0 (flags O_RDONLY)
7417 15:04:00.002165 fcntl(49, F_SETFL, O_RDONLY|O_NONBLOCK <unfinished ...>
7417 15:04:00.002222 <... fcntl resumed> ) = 0
7417 15:04:00.003052 fcntl(49, F_GETFL <unfinished ...>
7417 15:04:00.003195 <... fcntl resumed> ) = 0x800 (flags O_RDONLY|O_NONBLOCK)
...
7417 15:04:00.237131 fcntl(49, F_GETFL) = 0x800 (flags O_RDONLY|O_NONBLOCK)
7417 15:04:00.237363 epoll_ctl(4, EPOLL_CTL_ADD, 49, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=49, u64=12923050543437316145}} <unfinished ...>
7417 15:04:00.237478 <... epoll_ctl resumed> ) = 0
...
7417 15:04:00.274482 read(49, <unfinished ...>
7417 15:04:00.274558 <... read resumed> "\0\0\0\25", 4) = 4
7417 15:04:00.274670 read(49, <unfinished ...>
7417 15:04:00.274734 <... read resumed> "(I15\n(I9395\ntp0\ntp1\n.", 21) = 21
7417 15:04:00.274851 epoll_ctl(4, EPOLL_CTL_ADD, 49, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=49, u64=12923050543437316145}} <unfinished ...>
7417 15:04:00.274970 <... epoll_ctl resumed> ) = -1 EEXIST (File exists)
...
... from here fd 49 is used normally for a while, have not included all the output ...
...
7417 15:04:52.871646 epoll_wait(4, [{EPOLLIN, {u32=49, u64=12923050543437316145}}, {EPOLLIN, {u32=33, u64=12923050543437316129}}, {EPOLLOUT, {u32=48, u64=12923050543437316144}}, {EPOLLOUT, {u32=8, u64=12923050543437316104}}], 1023, 155) = 4
7417 15:04:52.871888 read(49, "\0\0\0\31", 4) = 4
7417 15:04:52.872079 read(49, "(I4\n(I9400\nI155\ntp0\ntp1\n.", 25) = 25
... here it uses normal poll for a once?
7417 15:04:52.891818 poll([{fd=49, events=POLLERR}], 1, 10 <unfinished ...>
7417 15:04:52.902239 <... poll resumed> ) = 0 (Timeout)
7417 15:04:52.913780 close(49 <unfinished ...>
7417 15:04:52.914020 <... close resumed> ) = 0
... here we create a new pipe for a child process
7417 15:04:53.148195 pipe([49, 50]) = 0
7417 15:04:53.148996 clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f2dee7f79d0) = 9482
... the write end got closed, now we dup it. This is the sentinal fd so is not marked non-blocking
7417 15:04:53.155409 dup(49) = 50
7417 15:04:53.156030 epoll_ctl(4, EPOLL_CTL_ADD, 50, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=50, u64=12923050543437316146}}) = 0
... and here it breaks
7417 15:04:53.776974 epoll_wait(4, <unfinished ...>
7417 15:04:53.785786 <... epoll_wait resumed> [{EPOLLHUP, {u32=49, u64=12923050543437316145}}], 1023, 1878) = 1
7417 15:04:53.785876 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9481, si_uid=905, si_status=155, si_utime=4, si_stime=3} ---
7417 15:04:53.786073 read(49, <unfinished ...>
... discontinuity ...
7417 15:09:24.338109 <... read resumed> 0x23f4f10, 4) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
7417 15:09:24.345507 epoll_ctl(4, EPOLL_CTL_DEL, 49, 0x7ffeecbf7660) = -1 ENOENT (No such file or directory)
Note how epoll() admits that fd 49 is no longer in its fdset, but it returned the number nonetheless.
The way to fix this is to ensure that in the worker every file descriptor is closed that is being monitored by epoll(). Currently workers close the file descriptors they don't want that correspond to themselves, but they don't touch the file descriptors they inherit that relate to other workers. Workarounds are to mark the sentinal fd also as non-blocking, or simply using poll() instead of epoll(). I'm testing the latter locally.
Ok, as it turns out, using poll() doesn't solve the problem. As the actual issue is that a file descriptor is being closed while still registered with the hub. Once you realise that it is easy to figure out exactly where it goes wrong and the following hack fixes this issue for us. Without this we could reproduce the issue within an hour or two. With it we haven't been able to trigger it yet. The hack is not the correct fix, but it really requires someone who knows the code better to write a good fix.
--- /usr/local/lib/python2.7/dist-packages/celery/concurrency/asynpool.py~ 2018-03-16 01:10:04.000000000 +0000
+++ /usr/local/lib/python2.7/dist-packages/celery/concurrency/asynpool.py 2018-03-16 12:08:58.058686003 +0000
@@ -735,6 +735,7 @@
except KeyError:
pass
self.on_inqueue_close = on_inqueue_close
+ self.hub_remove = hub_remove
def schedule_writes(ready_fds, total_write_count=[0]):
# Schedule write operation to ready file descriptor.
@@ -1241,6 +1242,7 @@
if queue:
for sock in (queue._reader, queue._writer):
if not sock.closed:
+ self.hub_remove(sock)
try:
sock.close()
except (IOError, OSError):
It looks like the write queue fd is properly removed from the hub (a few lines up), but the read queue fd is not.