Go to file
Alex Vandiver 3cbbf2307b thumbnail: Only lock the message row, not the Attachment row.
This prevents a deadlock between the thumbnailing worker and message
sending, as follows:

1. A user uploads an image, making Attachment and ImageAttachment
   rows, as well as enqueuing a job in the thumbnailing queue.

2. Message sending starts a transaction, creates the Message row,
   and calls `do_claim_attachments`, which edits the Attachment row
   of the upload (implicitly locking it).

3. The thumbnailing worker starts a transaction, locks the
   ImageAttachment row for its image, thumbnails it, and then
   attempts to `select_for_update()` the message objects (joined to
   the Attachments table) to find the ones which link to the
   attachment in question. This query blocks, since "a locking
   clause without a table list affects all tables used in the
   statement"[^1] and the message-send request already has a write
   lock on the Attachments row in question.

4. The message-send request attempts to re-fetch the ImageAttachment
   row inside the transaction, which tries to pull a lock on it.

5. Deadlock, because the message-send request has the Attachment
   lock, and waits for the ImageAttachment lock; the thumbnailing
   worker has the ImageAttachment lock, and waits for the Attachment
   lock.

We break this deadlock by limiting the
`update_message_rendered_content` `select_for_update` to only take
the lock on the Message table, and not also the Attachments table --
no changes will be made to the Attachments, so no lock is necessary
there. This allows the thumbnailing worker to successfully pull the
empty list of messages (since the message-send request has not
commits its transaction, and thus the Message row is not visible
yet), and release its ImageAttachment lock so that the message-send
request can proceed.

[^1]: https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE
2024-10-04 09:10:14 -07:00
.github ci: Test upgrades from Noble and 9.0. 2024-07-26 14:25:49 -07:00
.tx
.vscode
analytics audit-log: Move subscription event types to AuditLogEventType enum. 2024-09-09 11:50:13 -07:00
api_docs realm: Remove user_group_edit_policy from the backend. 2024-10-01 17:35:14 -07:00
confirmation migrations: Squash most confirmation migrations. 2024-08-23 17:15:35 -07:00
corporate analytics: Pass subgroup=None to improve indexing. 2024-10-02 14:11:44 -04:00
docs help: Link to "Moving to Zulip" guide in help center and prod docs. 2024-09-30 11:58:31 -07:00
help help: Refer to group settings for create/manage group at org level. 2024-10-03 15:18:40 -07:00
help-beta dependencies: Upgrade JavaScript dependencies. 2024-10-04 08:47:07 -07:00
locale i18n: Update translation data from Transifex. 2024-07-25 12:34:41 -07:00
patches dependencies: Upgrade JavaScript dependencies. 2024-10-04 08:47:07 -07:00
pgroonga migrations: Import BaseDatabaseSchemaEditor from its canonical module. 2023-03-05 14:46:28 -08:00
puppet puppet: Upgrade sentry-cli. 2024-09-30 11:24:36 -07:00
requirements requirements: Upgrade Python requirements. 2024-09-24 19:27:21 -07:00
scripts upload: Use tusd for resumable, larger uploads. 2024-09-19 11:37:29 -07:00
static landing-page: Update streams_and_topics_day images. 2024-09-26 09:27:01 -07:00
stubs/taint endpoints: Remove the has_request_variables decorator. 2024-09-05 16:02:12 -07:00
templates docs: Add missing links to web-public channels in dev community. 2024-10-03 09:15:51 -07:00
tools user_groups: Check permission to manage groups based on group setting. 2024-10-01 17:35:14 -07:00
var/puppeteer
web settings: Do not store pill widgets for new groups in map. 2024-10-04 08:48:03 -07:00
zerver thumbnail: Only lock the message row, not the Attachment row. 2024-10-04 09:10:14 -07:00
zilencer settings: Add group_creator as default for can_manage_group. 2024-10-01 17:35:14 -07:00
zproject saved_snippets: Add backend for saved snippets. 2024-09-24 15:27:58 -07:00
.codecov.yml
.codespellignore codespell: Fix spelling mistakes caught by codespell. 2024-05-31 14:32:33 -07:00
.editorconfig editorconfig: Use [[shell]] section for shfmt options. 2024-02-22 16:36:16 -05:00
.eslintignore web: Move web app to ‘web’ directory. 2023-02-23 16:04:17 -08:00
.eslintrc.js dependencies: Upgrade JavaScript dependencies. 2024-10-04 08:47:07 -07:00
.gitattributes
.gitignore tsconfig: Enable composite. 2024-06-09 12:08:03 -07:00
.gitlint lint: Update line-length for commit message to 72 in gitlint. 2023-05-01 10:35:52 -07:00
.mailmap mailmap: Canonicalize name for Kunal Sharma. 2024-07-25 11:23:44 -07:00
.npmignore
.npmrc dependencies: Switch to pnpm. 2023-03-20 15:48:29 -07:00
.prettierignore marked: Fix type stub to declare marked as a CommonJS module. 2024-06-08 00:26:38 -07:00
.pyre_configuration
.readthedocs.yaml
.sonarcloud.properties
CODE_OF_CONDUCT.md linter: Add check for comma after "e.g." in md files. 2024-07-05 15:36:24 -07:00
CONTRIBUTING.md contributor docs: Clarify how to claim a mobile issue 2024-10-03 16:45:50 -07:00
Dockerfile-postgresql docs: Fix grammar errors found by mwic. 2023-10-09 13:24:09 -07:00
LICENSE
NOTICE
README.md docs: Update Black and isort references to Ruff. 2024-07-17 18:33:21 -07:00
SECURITY.md docs: Update .html links pointing to "Upgrade Zulip" or "Modify Zulip". 2023-08-11 16:49:32 -07:00
Vagrantfile Upgrade development environment to Ubuntu 22.04. 2024-04-01 13:27:39 -07:00
manage.py ruff: Fix UP007 Use `X | Y` for type annotations. 2024-07-13 22:28:22 -07:00
package.json dependencies: Upgrade JavaScript dependencies. 2024-10-04 08:47:07 -07:00
pnpm-lock.yaml dependencies: Upgrade JavaScript dependencies. 2024-10-04 08:47:07 -07:00
pnpm-workspace.yaml help-beta: Create initial starlight project. 2024-08-02 18:18:01 -07:00
prettier.config.js
pyproject.toml restart-server: Wait until chain reload has completed. 2024-08-29 12:12:34 -07:00
stylelint.config.js dependencies: Upgrade JavaScript dependencies. 2023-07-21 15:58:42 -07:00
tsconfig.json help-beta: Create initial starlight project. 2024-08-02 18:18:01 -07:00
version.py dependencies: Upgrade JavaScript dependencies. 2024-10-04 08:47:07 -07:00

README.md

Zulip overview

Zulip is an open-source team collaboration tool with unique topic-based threading that combines the best of email and chat to make remote work productive and delightful. Fortune 500 companies, leading open source projects, and thousands of other organizations use Zulip every day. Zulip is the only modern team chat app that is designed for both live and asynchronous conversations.

Zulip is built by a distributed community of developers from all around the world, with 74+ people who have each contributed 100+ commits. With over 1000 contributors merging over 500 commits a month, Zulip is the largest and fastest growing open source team chat project.

Come find us on the development community chat!

GitHub Actions build status coverage status Mypy coverage Ruff code style: prettier GitHub release docs Zulip chat Twitter GitHub Sponsors

Getting started

You may also be interested in reading our blog, and following us on Twitter and LinkedIn.

Zulip is distributed under the Apache 2.0 license.