Skip to content

Check potential races when updating sessions. - #144

Merged
gsaluja9 merged 3 commits into
developfrom
feature/threaded_session
Oct 5, 2022
Merged

gsaluja9 merged 3 commits into
developfrom
feature/threaded_session

Conversation

@gsaluja9

@gsaluja9 gsaluja9 commented Oct 3, 2022

Copy link
Copy Markdown
Contributor

No description provided.

@gsaluja9
gsaluja9 requested review from drewaogle and luisremis and removed request for luisremis October 3, 2022 14:24

@drewaogle drewaogle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks super useful, just had 2 questions!

Comment thread aperturedb/Connector.py Outdated

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we make the 10 a variable we define at the top like SESSION_EXPIRTY_OFFSET_SEC ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will do

Comment thread aperturedb/Connector.py
return

if not self.session.valid():
if not self.shared_data.session.valid():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@gsaluja9
gsaluja9 requested a review from drewaogle October 5, 2022 02:25
Comment thread aperturedb/Connector.py Outdated
raise UnauthorizedException(response)

with self.shared_data.lock:
self.shared_data.session = Session(session_info["session_token"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could maybe do a check of valid here?

Comment thread aperturedb/Connector.py Outdated

if not self.session.valid():
if not self.shared_data.session.valid():
self._refresh_token()

@drewaogle drewaogle Oct 5, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what I was thinking was

Suggested change
self._refresh_token()
with self.shared_data.session.lock:
if not self.shared_data.session.valid():
self._refresh_token()

@drewaogle drewaogle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks great

@gsaluja9
gsaluja9 merged commit 15f2f14 into develop Oct 5, 2022
@gsaluja9
gsaluja9 deleted the feature/threaded_session branch September 14, 2023 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants