zulip/zerver
Alex Vandiver 3efed5f1e6 queue_processors: Shut down background missedmessage_emails thread.
Python's behaviour on `sys.exit` is to wait for all non-daemon threads
to exit.  In the context of the missedmessage_emails worker, if any
work is pending, a non-daemon Timer thread exists, which is waiting
for 5 seconds.  As soon as that thread is serviced, it sets up another
5-second Timer, a process which repeats until all
ScheduledMessageNotificationEmail records have been handled.  This
likely takes two minutes, but may theoretically take up to a week
until the thread exits, and thus sys.exit can complete.

Supervisor only gives the process 30 seconds to shut down, so
something else must prevent this endless Timer.

When `stop` is called, take the lock so we can mutate the timer.
However, since `stop` may have been called from a signal handler, our
thread may _already_ have the lock.  As Python provides no way to know
if our thread is the one which has the lock, make the lock a
re-entrant one, allowing us to always try to take it.

With the lock in hand, cancel any outstanding timers.  A race exists
where the timer may not be able to be canceled because it has
finished, maybe_send_batched_emails has been called, and is itself
blocked on the lock.  Handle this case by timing out the thread join
in `stop()`, and signal the running thread to exit by unsetting the
timer event, which will be detected once it claims the lock.
2021-11-23 10:45:49 -08:00
..
data_import data_import: Ignore Rocket.Chat livechat streams/messages. 2021-11-07 09:50:55 -08:00
integration_fixtures/nagios tests: Add a test for fixtures for non-webhook integrations. 2021-04-28 08:16:51 -07:00
lib api: Prevent special characters in topics. 2021-11-22 22:09:06 -08:00
management rate_limit: Add a flag to lump all TOR exit node IPs together. 2021-11-16 11:42:00 -08:00
migrations realm: Add option to enable/disable spectator login. 2021-11-18 12:55:12 -08:00
openapi api_documentation: Fix `/update-subscription-settings` api doc. 2021-11-22 11:50:27 -08:00
tests api: Prevent special characters in topics. 2021-11-22 22:09:06 -08:00
tornado tornado: Move SIGTERM shutdown handler into a callback. 2021-11-12 09:57:23 -08:00
views realm: Add option to enable/disable spectator login. 2021-11-18 12:55:12 -08:00
webhooks webhooks/github: Include discussion ID in messages. 2021-10-26 17:52:57 -07:00
worker queue_processors: Shut down background missedmessage_emails thread. 2021-11-23 10:45:49 -08:00
__init__.py django: Upgrade Zulip to Django 3.2 LTS. 2021-05-03 08:36:22 -07:00
apps.py caching: Make sender type optional for flush_cache. 2021-07-26 14:48:07 -07:00
context_processors.py realm: Add option to enable/disable spectator login. 2021-11-18 12:55:12 -08:00
decorator.py rate_limit: Add a flag to lump all TOR exit node IPs together. 2021-11-16 11:42:00 -08:00
filters.py typing: Fix function signatures. 2021-08-20 05:54:19 -07:00
forms.py reset_password: Show user-facing page on rate-limit. 2021-11-04 20:34:39 -07:00
logging_handlers.py logging_handlers: Remove STAGING_ERROR_NOTIFICATIONS setting. 2021-07-07 09:26:02 -07:00
middleware.py lint: Fix typos found by codespell. 2021-10-19 16:51:13 -07:00
models.py realm: Add option to enable/disable spectator login. 2021-11-18 12:55:12 -08:00
signals.py python: Convert deprecated Django ugettext alias to gettext. 2021-04-15 18:01:34 -07:00