Skip to content
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

[Session] Reset global agent on expire #3838

Merged
merged 1 commit into from
May 3, 2024
Merged

[Session] Reset global agent on expire #3838

merged 1 commit into from
May 3, 2024

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented May 3, 2024

Fixes a mistake I introduced in #3836.
Extracted from #3728.

The change in #3836 assumes the persistence handler will handle any errors. However, our onAgentSessionChange persistence handler does not currently update __globalAgent on expiry (despite updating the related state). This is inconsistent with how the same persistence handler treats network-error (for which it does update __globalAgent).

Updating the global agent seems like the correct behavior if we're updating the UI to show PWI. So this seems like an omission in the existing code (which #3836 made worse). I suppose this was less important before #3836 because the catch branch would restore __globalAgent regardless of the persistence handler. Anyway, this fix is in the handler itself.

In this PR, I adjust the expired branch to do the same things (copy paste) as the network-error early condition. (Unlike with network-error, we don't want an early return because we still want the accounts-related state update below to run.)

Test Plan

To trigger the expiry codepath, you can set a breakpoint in resumeSession and evaluate res.data.did = 'foo' so that it raises an error which the agent will broadcast as an expiry.

Verify that previously __globalAgent was being set in this case by the catch block I removed in #3836. So now it's not being set at all, and you can verify it's stale.

After applying this PR and doing the same thing, verify that __globalAgent is being set by the persisted handler.

Verify you get kicked to the login and can log in after entering credentials.

Copy link

render bot commented May 3, 2024

did: undefined,
}
: s.currentAgentState,
currentAgentState: s.currentAgentState,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is now handled by the above setState so we can just carry over its state.

Copy link

github-actions bot commented May 3, 2024

Old size New size Diff
6.86 MB 6.86 MB 89 B (0.00%)

Copy link
Contributor

@haileyok haileyok left a comment

Choose a reason for hiding this comment

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

Yep, was able to verify that. Looking good.

@gaearon gaearon merged commit 1e484c6 into main May 3, 2024
6 checks passed
@gaearon gaearon deleted the agent-fixes-more branch May 3, 2024 12:46
estrattonbailey added a commit that referenced this pull request May 3, 2024
* origin/main:
  make service url gate friendlier (#3841)
  remove broken keyboard offset code (#3842)
  [Clipclops] Header tweaks (#3839)
  update date logic to account for timezones (#3840)
  [Clipclops] Moar error (#3837)
  [Session] Reset global agent on expire (#3838)
  [Session] Rely on agent session change event for persisting resumed session (#3836)
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