Skip to content

log and drop found user when in an invalid state for caching - #6940

Closed
shiftkey wants to merge 4 commits into
developmentfrom
dont-trust-the-cache
Closed

shiftkey wants to merge 4 commits into
developmentfrom
dont-trust-the-cache

Conversation

@shiftkey

Copy link
Copy Markdown
Member

Overview

Adding some resiliency and tracing to GitHubUserStore._loadAndCacheUser because I don't entirely trust what it's trying to cache.

Related to #6313 but I don't quite follow how it would result in a disabled app menu

Description

Keep in mind the original issue that the app is calling this function and one of these fields is undefined:

function userWithLowerCase(user: IGitHubUser): IGitHubUser {
return {
...user,
email: user.email.toLowerCase(),
login: user.login.toLowerCase(),
}
}

The stack trace from #6313 mentions these three functions (albeit minified to strip the function names): GitHubUserStore._loadAndCacheUser -> GitHubUserStore.cacheUser -> userWithLowerCase.

And cacheUser is invoked only when it finds a valid object for gitUser:

if (gitUser) {
await this.cacheUser(gitUser)
this.emitUpdate()
} else {
this.failedRequests.add(key)
}

So what is _loadAndCacheUser doing that might be risky?

  • retrieve a cached user based on the received email address
  • if nothing found, use the GitHub API to find the author - using the given commit and email address

My working theory here is that one of these operations is returning a user with an empty login, which is triggering the action. The app can work fine without finding an user here, so this PR changes the behaviour of this area to:

  • emit a clear error message when it encounters a gitUser that's an invalid state, with details to help us isolate the issue if it gets reported
  • when the app encounters this invalid gitUser, it clears the variable so the app doesn't try and cache it

Armed with more details about this issue from someone who has encountered #6313, we can make this area more reliable once we know what piece of data we're missing...

Release notes

Notes:

public async _loadAndCacheUser(
accounts: ReadonlyArray<Account>,
repository: Repository,
sha: string | null,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can drop the | null here because there's no longer any caller that is passing in null, so we can simplify the code paths in findUserWithAPI.

@shiftkey
shiftkey marked this pull request as ready for review February 25, 2019 20:46
@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Feb 25, 2019
@shiftkey

Copy link
Copy Markdown
Member Author

Closing this out in favour of a more targeted fix now I have uncovered the root cause: #6313 (comment)

@shiftkey shiftkey closed this Feb 25, 2019
@shiftkey
shiftkey deleted the dont-trust-the-cache branch February 25, 2019 22:24

This branch was previously deployed

1 inactive deployment
test — e0c8004f Deployed Feb 25, 2019 by hubot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants