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

Defer most signal handling code until after the end of the current transaction #7460

Merged
merged 1 commit into from
Feb 13, 2024

Conversation

SpecLad
Copy link
Contributor

@SpecLad SpecLad commented Feb 8, 2024

Motivation and context

Non-database actions like deleting directories, sending webhooks, scheduling reports should only be done after the current transaction is committed. If we do it immediately, and the transaction is later aborted, then we will have (for example) sent a webhook about an event that didn't actually happen.

There's also a secondary benefit to moving this action outside of the transaction; the less time we spend inside a transaction, the better, since a transaction may lock out other clients from working on the affected DB rows.

In addition, prevent the affected actions from crashing the view handler with an exception (using the robust=True option). I don't think it's reasonable to (for example) return a 500 response to a PATCH request just because we failed to send the corresponding webhook.

There is one more type of action that should be modified in this way (sending events), but it would be easier to do that after a refactoring that I did in another patch, so I'll do it later.

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • [ ] I have updated the documentation accordingly
  • [ ] I have added tests to cover my changes
  • [ ] I have linked related issues (see GitHub docs)
  • [ ] I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

@SpecLad
Copy link
Contributor Author

SpecLad commented Feb 8, 2024

/check

Copy link
Contributor

github-actions bot commented Feb 8, 2024

❌ Some checks failed
📄 See logs here

@SpecLad SpecLad force-pushed the handle-after-transaction branch 2 times, most recently from e7124f7 to 1c3b2ad Compare February 9, 2024 11:07
@SpecLad
Copy link
Contributor Author

SpecLad commented Feb 9, 2024

/check

Copy link
Contributor

github-actions bot commented Feb 9, 2024

❌ Some checks failed
📄 See logs here

…ansaction

Non-database actions like deleting directories, sending webhooks, scheduling
reports should only be done after the current transaction is committed. If
we do it immediately, and the transaction is later aborted, then we will
have (for example) sent a webhook about an event that didn't actually
happen.

There's also a secondary benefit to moving this action outside of the
transaction; the less time we spend inside a transaction, the better, since
a transaction may lock out other clients from working on the affected DB
rows.

In addition, prevent the affected actions from crashing the view handler
with an exception (using the `robust=True` option). I don't think it's
reasonable to (for example) return a 500 response to a `PATCH` request just
because we failed to send the corresponding webhook.

There is one more type of action that should be modified in this way
(sending events), but it would be easier to do that after a refactoring
that I did in another patch, so I'll do it later.
@SpecLad SpecLad marked this pull request as ready for review February 9, 2024 15:46
Copy link

codecov bot commented Feb 9, 2024

Codecov Report

Merging #7460 (636c4d8) into develop (b4eed78) will decrease coverage by 0.03%.
Report is 4 commits behind head on develop.
The diff coverage is 85.71%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7460      +/-   ##
===========================================
- Coverage    83.59%   83.56%   -0.03%     
===========================================
  Files          374      374              
  Lines        39742    39755      +13     
  Branches      3731     3731              
===========================================
  Hits         33223    33223              
- Misses        6519     6532      +13     
Components Coverage Δ
cvat-ui 79.47% <ø> (-0.06%) ⬇️
cvat-server 87.33% <85.71%> (-0.01%) ⬇️

Copy link
Contributor

@Marishka17 Marishka17 left a comment

Choose a reason for hiding this comment

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

LGTM

@SpecLad SpecLad merged commit f477e0b into cvat-ai:develop Feb 13, 2024
43 checks passed
@SpecLad SpecLad deleted the handle-after-transaction branch February 13, 2024 13:43
bsekachev pushed a commit that referenced this pull request Feb 13, 2024
…ansaction (#7460)

Non-database actions like deleting directories, sending webhooks,
scheduling reports should only be done after the current transaction is
committed. If we do it immediately, and the transaction is later
aborted, then we will have (for example) sent a webhook about an event
that didn't actually happen.

There's also a secondary benefit to moving this action outside of the
transaction; the less time we spend inside a transaction, the better,
since a transaction may lock out other clients from working on the
affected DB rows.

In addition, prevent the affected actions from crashing the view handler
with an exception (using the `robust=True` option). I don't think it's
reasonable to (for example) return a 500 response to a `PATCH` request
just because we failed to send the corresponding webhook.

There is one more type of action that should be modified in this way
(sending events), but it would be easier to do that after a refactoring
that I did in another patch, so I'll do it later.
SpecLad added a commit that referenced this pull request Feb 15, 2024
This is a small addendum to #7460, which I couldn't include in that PR,
because it was blocked by #7430.
@cvat-bot cvat-bot bot mentioned this pull request Feb 23, 2024
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