Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent deadlock during command deletion in MySQL #61

Merged
merged 1 commit into from
Dec 22, 2022

Conversation

4e554c4c
Copy link
Contributor

NanoMDM allows for a single command to be queued for multiple devices. Since #48 landed, both queued commands and the command data itself is deleted after a device in finished with a command. However, I have observed deadlocks which occur when multiple devices trigger deletion for a shared command at once.
This can be avoided by placing a record lock on the command row before attempting a delete, so that only one device's enrollment queue can be cleared at a time.

This should have minimal impacts on performance as it will only serialize deletes to a single command. Furthermore, as the lock on the command record must be taken anyway, this does not add any additional locking to the transaction.

Testing

I have tested this, and have confirmed that it prevents deadlocks in NanoMDM. Furthermore, I have tested that commands are still delivered and responded to.

NanoMDM allows for a single command to be queued for multiple devices.
Since micromdm#48 landed, both queued commands and the command data itself is
deleted after a device in finished with a command.
However, I have observed deadlocks which occur when multiple devices
trigger deletion for a shared command at once.
This can be avoided by placing a record lock on the command row before
attempting a delete, so that only one device's enrollment queue can be
cleared at a time.

This should have minimal impacts on performance as it will only
serialize deletes to a single command. Furthermore, as the lock on the
command record must be taken anyway, this does not add any additional
locking to the transaction.

Testing:
I have tested this, and have confirmed that it prevents deadlocks in
NanoMDM. Furthermore, I have tested that commands are still delivered
and responded to.
@4e554c4c 4e554c4c marked this pull request as ready for review December 16, 2022 23:32
Copy link
Member

@jessepeterson jessepeterson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thanks!

@jessepeterson jessepeterson merged commit c90f186 into micromdm:main Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants