Repository navigation
Check potential races when updating sessions. - #144
Conversation
drewaogle
left a comment
There was a problem hiding this comment.
Looks super useful, just had 2 questions!
|
|
||
| if session_age > self.session_token_ttl: | ||
| # This triggers refresh if the session is about to expire. | ||
| if session_age > self.session_token_ttl - 10: |
There was a problem hiding this comment.
can we make the 10 a variable we define at the top like SESSION_EXPIRTY_OFFSET_SEC ?
| return | ||
|
|
||
| if not self.session.valid(): | ||
| if not self.shared_data.session.valid(): |
There was a problem hiding this comment.
do we want to think about locking around the test? It could be possible to have a thread start refreshing, then have another enter and do another refresh.
Or perhaps we should retest after locking in _refresh_token?
There was a problem hiding this comment.
The _refresh_token is only called from within _check_session_status, via _renew_session, which has the logic to try this in case of any failures.
I chose to implement it this way so that we do not have a lock around a bigger section.
| raise UnauthorizedException(response) | ||
|
|
||
| with self.shared_data.lock: | ||
| self.shared_data.session = Session(session_info["session_token"], |
There was a problem hiding this comment.
could maybe do a check of valid here?
|
|
||
| if not self.session.valid(): | ||
| if not self.shared_data.session.valid(): | ||
| self._refresh_token() |
There was a problem hiding this comment.
what I was thinking was
| self._refresh_token() | |
| with self.shared_data.session.lock: | |
| if not self.shared_data.session.valid(): | |
| self._refresh_token() |
No description provided.