Agniva De Sarker 23dd4a5946 MM-31396: Fix a possible deadlock with SidebarCategories (#17109)
This is a deadlock due to reversed locking order of the SidebarChannels
and SidebarCategories table.

I could not find the exact culprit query from the deadlock output
because it only shows the last query a transaction is running. And from looking
at the code, the only query that runs "UPDATE SidebarCategories SET DisplayName = ?, Sorting = ? WHERE Id = ?"
is UpdateSidebarCategories. But for the deadlock to happen, it has to lock
SidebarChannels _first_, and then _then_ lock SidebarCategories.

Looking a bit more throughly, I found that DeleteSidebarCategory does indeed
lock the tables in an inverse way and if DeleteSidebarCategory runs concurrently with
UpdateSidebarCategories, they will deadlock.

Here's how it will happen.

```
tx1
DELETE FROM SidebarChannels WHERE CategoryId = 'xx';

tx2
UPDATE SidebarCategories SET DisplayName='dn' WHERE Id='xx';

tx2
DELETE FROM SidebarChannels WHERE (ChannelId IN ('yy') AND CategoryId = 'xx');

tx1
DELETE FROM SidebarCategories WHERE Id = 'xx';
```

And then we see:
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction

To fix this, we simply reorder the Delete query to lock the SidebarCategories first,
and then SidebarChannels.

In fact, any transaction updating/deleting rows from those two tables should always operate on that order
if possible.

https://mattermost.atlassian.net/browse/MM-31396

```release-note
Fixed a database deadlock that can happen if a sidebar category is updated and deleted at the same time.
```
2021-03-16 15:07:30 +05:30
2021-02-21 08:22:27 +01:00
2021-01-04 15:21:01 +01:00
2021-03-16 12:48:20 +05:30
2021-03-05 09:18:37 +01:00
2020-01-23 12:34:29 +01:00
2021-03-12 12:37:30 -05:00
2021-03-05 09:18:37 +01:00
2021-03-16 12:48:20 +05:30
2021-03-16 12:48:20 +05:30
2021-03-12 12:37:30 -05:00
2021-03-16 12:48:20 +05:30
2021-03-05 09:18:37 +01:00
2020-03-13 18:35:31 +01:00
2019-04-04 09:49:07 -04:00
2021-01-14 18:21:21 +01:00
2021-03-16 12:48:20 +05:30
2018-05-30 10:23:25 -04:00
2021-03-09 11:26:42 +05:30
2021-03-09 11:26:42 +05:30
2021-01-22 19:40:37 +01:00

Mattermost

Mattermost is an open source, private cloud, Slack-alternative from https://mattermost.com.

It's written in Golang and React and runs as a single Linux binary with MySQL or PostgreSQL. Every month on the 16th a new compiled version is released under an MIT license.

screenshot at nov 29 14-11-32

Table of Contents

Try out Mattermost

Deploy on Heroku

Deploy a Preview

Note: Heroku preview does not include email or persistent storage

Deploy on a Cloud Platform via Bitnami

Auto-deploy Mattermost to Amazon Web Services, Azure, Google Cloud Platform, or Oracle Cloud Platform via Bitnami.

Install on Your Own Machine

Native Mobile and Desktop Apps

In addition to the web interface, you can also download Mattermost clients for Android, iOS, Windows PC, Mac OSX, and Linux.

Google Play App Store Windows PC Mac OSX Linux

Get Security Bulletins

Receive notifications of critical security updates. The sophistication of online attackers is perpetually increasing. If you are deploying Mattermost it is highly recommended you subscribe to the Mattermost Security Bulletin mailing list for updates on critical security releases.

Get Involved

Learn More

License

See the LICENSE file for license rights and limitations.

Get the Latest News

Contributing

Please see CONTRIBUTING.md.

Any other questions, mail us at info@mattermost.com. Wed love to meet you!

Description
Mattermost is an open source platform for secure collaboration across the entire software development lifecycle..
Readme 1.2 GiB
Languages
TypeScript 46.9%
Go 40.2%
JavaScript 8.6%
SCSS 2.8%
HTML 1.1%
Other 0.3%