Replies: 13 comments 3 replies
-
Why is Also from my quick glance at Maybe removing this division and the |
Beta Was this translation helpful? Give feedback.
-
We've been iterating on this previously here. I personally avoid this issue by using a wrapper over |
Beta Was this translation helpful? Give feedback.
-
I'm certainly open to improving and changing this. The reason we have to use interior mutability is because the underlying |
Beta Was this translation helpful? Give feedback.
-
Seems like not In reality a simpler change to just fix this problem would possibly be to use some kind of reentrant/recursive lock. There's no recursive |
Beta Was this translation helpful? Give feedback.
-
Yes, I knew that I'm certainly not against a new API. A fairly simple solution is what I mentioned above (the wrapper over |
Beta Was this translation helpful? Give feedback.
-
@Ptrskay3 yes, seems reasonable in my opinion. |
Beta Was this translation helpful? Give feedback.
-
Another thing to point out here is that it's unclear how often users are going to run into this in practice. It's a bigger issue with Additionally, it may be worth investigating with |
Beta Was this translation helpful? Give feedback.
-
@maxcountryman correct me if I'm wrong, but I think the If there's some way to forbid this situation in the code - a compilation error or even a runtime panic in the worst case - this issue is solved without any major changes to the API. We'd just need to change the docs slightly. |
Beta Was this translation helpful? Give feedback.
-
I think it's a fairly common thing to both read from and write to the session in the same handler. A straight forward examples are OAuth or Two-factor authentication. In my opinion the root cause of this issue is in this repository, and this is where it should be addressed - that's why I opened the issue here.
|
Beta Was this translation helpful? Give feedback.
-
I would propose replacing the The handle is added as Guards should only be acquired as long as they are needed, and dropped afterwards. Or did I miss anything in my CSRF synchronizer token middleware? The write guard is dropped before calling the inner service. |
Beta Was this translation helpful? Give feedback.
-
This is possible, but I'm not sure how obvious the API is. The tradeoff is the caller needs to directly manage the guard. This might be fine (it does make it explicit which seems to be part of the problem of abstraction here). To your point, this is already possible with the current implementation: applications can choose to use the |
Beta Was this translation helpful? Give feedback.
-
Folks on this thread, I started a separate discussion regarding |
Beta Was this translation helpful? Give feedback.
-
Hi folks, I've just published tower-sessions 0.1.0. It does away with the readable and writable pattern and moves towards a pattern whereby an inner state is held behind a mutex. This is the same pattern other successful tower middleware use, like tower-cookies. Importantly, this lock is only ever held during an operation over the inner hash map state. It also brings the implementation of the session into the crate itself. This means we'll no longer be dependent on external changes in order to address issues as they might arise. I suspect this design is far more robust than our current design and my hope is that we can migrate the vast majority of axum-sessions users to this new crate. Please let me know what you all think. |
Beta Was this translation helpful? Give feedback.
-
Having read an issue in axum-login I realized that it's really easy to get a deadlock with the current API of this crate. Since
ReadableSession
andWritableSession
both using the same underlying resource behind anRwLock
.A simple axum handler to reproduce:
and this can be solved if you release the lock guard
This issue becomes especially awkward and more subtle when this becomes an implicit bound, just like here.
AuthContext
needs a write access, but also there's a session read in the same handler. The developer must be familiar with the implementation details of these structs to know to release the read guard.I don't really know how to solve this with the current API, but I'm experimenting..
Beta Was this translation helpful? Give feedback.
All reactions