maxcountryman / tower-sessions

🥠 Sessions as a `tower` and `axum` middleware.
MIT License
233 stars 43 forks source link

fix session saving and loading data race #36

Closed maxcountryman closed 11 months ago

maxcountryman commented 11 months ago

This is a temporary fix for a data race that occurs when a session is saved and loaded at the same time. The result of this race is that stale data can be loaded into memory, resulting in potential data loss where multiple requests using the same session are issued simultaneously.

Here we address this by holding a lock for the duration of the request. This solution is only temporary, as the underlying session implementation can instead be modified to ensure safe access between the save and load await points.

This supercedes #35.

codecov[bot] commented 11 months ago

Codecov Report

Merging #36 (f31a249) into main (811a9c1) will decrease coverage by 0.78%. The diff coverage is 75.00%.

@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
- Coverage   78.55%   77.77%   -0.78%     
==========================================
  Files          13       13              
  Lines         415      423       +8     
==========================================
+ Hits          326      329       +3     
- Misses         89       94       +5     
Files Coverage Δ
src/mongodb_store.rs 93.54% <ø> (-3.12%) :arrow_down:
src/sqlx_store/mysql_store.rs 94.73% <ø> (-2.57%) :arrow_down:
src/sqlx_store/postgres_store.rs 85.71% <ø> (-2.10%) :arrow_down:
src/sqlx_store/sqlite_store.rs 83.78% <ø> (-2.33%) :arrow_down:
src/service.rs 72.60% <75.00%> (+0.13%) :arrow_up: