-
Notifications
You must be signed in to change notification settings - Fork 125
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
Send the state to the Session backend. #468
Conversation
Thanks for the PR! Can you please fix the issues reported by travis - that is, the test code needs to be updated and after that you'll need to run |
Codecov Report
@@ Coverage Diff @@
## master #468 +/- ##
==========================================
+ Coverage 85.01% 85.52% +0.51%
==========================================
Files 110 109 -1
Lines 5612 5582 -30
==========================================
+ Hits 4771 4774 +3
+ Misses 841 808 -33
Continue to review full report at Codecov.
|
I've now modified it so the Backend functions returned futures. This should allow for more flexibility when defining different backends. |
identifier: SessionIdentifier, | ||
content: &[u8], | ||
) -> Result<(), SessionError>; | ||
) -> Pin<Box<SetSessionFuture>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking so long to review this - I believe this type signature is incorrect? Without any lifetime information, the GetSessionFuture
type needs to live for 'static
, which it will not do if it accessed the state in an async context. I think this needs to be changed to something like
persist_session<'fut, 'a: 'fut, 'b: 'fut, 'c: 'fut>(
&'a self,
state: &'b State,
identifier: SessionIdentifier,
content: &'c [u8]
) -> Pin<Box<GetSessionFuture + 'fut>>
Alternatively, it might make sense to let #[async_trait]
deal with the lifetimes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, thanks for reviewing. I'll try to get to these shortly.
The last time I used #[async_trait]
it resulting in the rust compiler not being able to produce any decent error messages for any errors in the code that implemented those traits. We ended up changing back to returning Futures instead. Do you know if this problem has been resolved? I would be hesitant to use it unless it has..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only time I used #[async_trait]
was to run cargo expand
on it to see how it worked because I didn't want my proc macro to invoke another proc macro. So I don't know if this has been changed or has ever been a problem. However, I feel like the code would probably be more readable if we don't introduce this many lifetimes, but if you run into any incorrect/unhelpful error messages, just write the code the explicit way. I'm happy with both solutions.
&self, | ||
state: &State, | ||
identifier: SessionIdentifier, | ||
) -> Pin<Box<GetSessionFuture>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
&self, | ||
state: &State, | ||
identifier: SessionIdentifier, | ||
) -> Pin<Box<SetSessionFuture>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
Do you think you can get this PR ready? I'd like to include it in the next release. Let me know if you need any help. |
Hi, really sorry, I haven't had the chance to get to this. Life has taken over. I don't think I will get the chance to look at it any time soon either. I'm happy for someone else to take this on if they are willing, or we can just leave it and I will get to at it some point, whenever that may be! |
…tate Conflicts: gotham/src/middleware/session/backend/memory.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. I'm going to merge this as-is as it should work for most use cases, e.g. pulling a database connection out of the state and then enter an async block in which that connection is being used, and we can always improve it in the future.
This is for #467.
It sends the State to the
persist_session
,read_session
anddrop_session
methods of the Backend. This will be useful for additional backends, such as a Redis backend, that will need to access a connection that will be stored in the State.