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

Fix thread safety issue in patron_activity (PP-1155) #1793

Merged
merged 3 commits into from
Apr 18, 2024

Conversation

jonathangreen
Copy link
Member

@jonathangreen jonathangreen commented Apr 17, 2024

Description

This fixes a thread safety issue, where SQLAlchemy objects that are part of one thread's session are used in another thread. Leading to unpredictable behavior and deadlocks among the threads when under load. This was causing issues in the California CM instance when it was under increased load due to Aspen integration.

Motivation and Context

Resolve issues where threads and workers deadlock with each other, trying to update the patron information.

How Has This Been Tested?

  • Tested locally with CA DB and UWSGI
  • I wasn't able to make it deadlock, the way I see in production but I did see worker threads flushing changes from the main thread's Session.
  • This seems to indicate my hypothesis of session mixing is at least a possible cause here.

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@jonathangreen jonathangreen added the bug Something isn't working label Apr 17, 2024
@jonathangreen jonathangreen mentioned this pull request Apr 18, 2024
2 tasks
@jonathangreen jonathangreen force-pushed the bugfix/patron_activity_thread branch from 67607bf to 1f3fc57 Compare April 18, 2024 17:44
@jonathangreen jonathangreen requested a review from a team April 18, 2024 17:47
@jonathangreen jonathangreen marked this pull request as ready for review April 18, 2024 17:47
Copy link

codecov bot commented Apr 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.31%. Comparing base (8e97653) to head (1f3fc57).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1793   +/-   ##
=======================================
  Coverage   90.30%   90.31%           
=======================================
  Files         259      259           
  Lines       28659    28659           
  Branches     6514     6514           
=======================================
+ Hits        25881    25883    +2     
+ Misses       1840     1839    -1     
+ Partials      938      937    -1     
Flag Coverage Δ
Api 75.57% <ø> (+<0.01%) ⬆️
Core 59.79% <ø> (ø)
migration 24.08% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

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

🧵🚨 Looks great!

I made a couple minor edits to the main PR description.

@jonathangreen jonathangreen merged commit d8c38f6 into main Apr 18, 2024
24 checks passed
@jonathangreen jonathangreen deleted the bugfix/patron_activity_thread branch April 18, 2024 18:27
jonathangreen added a commit that referenced this pull request Apr 22, 2024
* Make patron_activity more thread safe.
* Move PatronActivityThread out
* Fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants