René's URL Explorer Experiment


Title: fix: Login - fix /api/v2/user cache race condition by bryphe-coder · Pull Request #47 · coder/coder · GitHub

Open Graph Title: fix: Login - fix /api/v2/user cache race condition by bryphe-coder · Pull Request #47 · coder/coder

X Title: fix: Login - fix /api/v2/user cache race condition by bryphe-coder · Pull Request #47 · coder/coder

Description: While I was testing the Sign-out functionality in #46 , I found a bug on login. Sometimes, intermittently, the login wouldn't 'take' even though the login POST was successful and the subsequent GET to /api/v2/user was successful - the user would still be brought to the /login screen a second time: ^ I log-in, and then the login screen just resets, and logging in a second time works 🤔 I tracked this down and found it is a new race condition that I inadvertently introduced when I migrated to SWR in #46. Because SWR caches responses based on the API path - we have to invalidate the cache for /api/v2/user when the user logins, otherwise we'll continue to serve the user-not-found error until SWR decides to retry. However, we weren't waiting for that cache-invalidation to go through - so there was the chance that an /api/v2/user request was still in-flight while we were redirecting after a successful login. If the request made it back prior to the redirect - login would work on the first try. If the request took longer - SWR would serve the stale, erroneous user from the cache. Luckily the fix is simple - mutate in the SWR API returns a promise, so we can just wait for that to go through before redirecting. Unfortunately, though, this is tricky to exercise in a unit test because with the SWR model, the login logic is spread between _app.tsx, UserContext.tsx, and SignInForm.tsx, and the race condition involves an integration of all of those places. I found that there is a lint rule that can help protect us from making this mistake - typescript-eslint/no-floating-promises (it's a lint rule we wanted to turn on in coder/m, too, actually - just a lot of work to clean up the code for it!), so I turned it on as part of this PR, and it caught a couple extra places to check.

Open Graph Description: While I was testing the Sign-out functionality in #46 , I found a bug on login. Sometimes, intermittently, the login wouldn't 'take' even though the login POST was successful and the su...

X Description: While I was testing the Sign-out functionality in #46 , I found a bug on login. Sometimes, intermittently, the login wouldn't 'take' even though the login POST was successfu...

Opengraph URL: https://github.com/coder/coder/pull/47

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:499f5571-ba79-7bac-d520-889311679174
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idECC0:38EE04:432FED:58E251:6B01976D
html-safe-nonce331c6cf0ddab84b50a7490b5dfd6c0b0588e212db986341ecf48b22dd6f5a2cd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQ0MwOjM4RUUwNDo0MzJGRUQ6NThFMjUxOjZCMDE5NzZEIiwidmlzaXRvcl9pZCI6IjM1MzQ4MDc3MTkwNDUzMzg5OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacfa539cc04221a1f7570a9b892471d642b902fa534731b2e2c06b4f831879dba9
hovercard-subject-tagpull_request:829195586
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/coder/coder/pull/47/files
twitter:imagehttps://avatars.githubusercontent.com/u/88213859?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/88213859?s=400&v=4
og:image:altWhile I was testing the Sign-out functionality in #46 , I found a bug on login. Sometimes, intermittently, the login wouldn't 'take' even though the login POST was successful and the su...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/coder/coder git https://github.com/coder/coder.git
octolytics-dimension-user_id95932066
octolytics-dimension-user_logincoder
octolytics-dimension-repository_id440752086
octolytics-dimension-repository_nwocoder/coder
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id440752086
octolytics-dimension-repository_network_root_nwocoder/coder
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/coder/coder/pull/47/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcoder%2Fcoder%2Fpull%2F47%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcoder%2Fcoder%2Fpull%2F47%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=coder%2Fcoder
Reloadhttps://github.com/coder/coder/pull/47/files
Reloadhttps://github.com/coder/coder/pull/47/files
Reloadhttps://github.com/coder/coder/pull/47/files
coderhttps://github.com/coder
coderhttps://github.com/coder/coder
Codehttps://github.com/coder/coder
Issues320 (320)https://github.com/coder/coder/issues
Pull requests470 (470)https://github.com/coder/coder/pulls
Discussionshttps://github.com/coder/coder/discussions
Actionshttps://github.com/coder/coder/actions
Projectshttps://github.com/coder/coder/projects
Security and quality49 (49)https://github.com/coder/coder/security
Insightshttps://github.com/coder/coder/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fcoder%2Fcoder%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fcoder%2Fcoder%2Fissues%2Fnew%2Fchoose
bryphe-coderhttps://github.com/bryphe-coder
mainhttps://github.com/coder/coder/tree/main
bryphe/fix/double-loginhttps://github.com/coder/coder/tree/bryphe/fix/double-login
Conversation 2 https://github.com/coder/coder/pull/47
Commits 3 https://github.com/coder/coder/pull/47/commits
Checks 0 https://github.com/coder/coder/pull/47/checks
Files changed https://github.com/coder/coder/pull/47/files
Please reload this pagehttps://github.com/coder/coder/pull/47/files
fix: Login - fix /api/v2/user cache race condition https://github.com/coder/coder/pull/47/files#top
Show all changes 3 commits https://github.com/coder/coder/pull/47/files
cb54a8a fix: Wait for /api/v2/user cache to expire prior to redirecting bryphe-coder Jan 22, 2022 https://github.com/coder/coder/pull/47/commits/cb54a8a8728e5bf544074d309e5e35977bcb5c3f
8b6b052 Enable no-floating-promises rule bryphe-coder Jan 22, 2022 https://github.com/coder/coder/pull/47/commits/8b6b052aeccc9543ab2e0031d2518acd3236bfde
61af313 Fix up additional floating promise cases bryphe-coder Jan 22, 2022 https://github.com/coder/coder/pull/47/commits/61af313fd1b533c705dcbe7f39a5426ff7bcd6e6
Clear filters https://github.com/coder/coder/pull/47/files
Please reload this pagehttps://github.com/coder/coder/pull/47/files
Please reload this pagehttps://github.com/coder/coder/pull/47/files
.eslintrc.yaml https://github.com/coder/coder/pull/47/files#diff-3894e4104cda190617684d0dc5d55e39e49c63cc6955edf4a446b91ae086bbd2
SignInForm.tsx https://github.com/coder/coder/pull/47/files#diff-1cbe9b77041934ab64b0029f915d9bc003f89fecb055b2fff3729fcb736b9287
UserContext.tsx https://github.com/coder/coder/pull/47/files#diff-34932539f99928fc852f6a604bc265fda6e783e696acfa37a19790d763c9fce8
.eslintrc.yamlhttps://github.com/coder/coder/pull/47/files#diff-3894e4104cda190617684d0dc5d55e39e49c63cc6955edf4a446b91ae086bbd2
View file https://github.com/coder/coder/blob/61af313fd1b533c705dcbe7f39a5426ff7bcd6e6/.eslintrc.yaml
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/coder/coder/pull/47/{{ revealButtonHref }}
https://github.com/coder/coder/pull/47/files#diff-3894e4104cda190617684d0dc5d55e39e49c63cc6955edf4a446b91ae086bbd2
https://github.com/coder/coder/pull/47/files#diff-3894e4104cda190617684d0dc5d55e39e49c63cc6955edf4a446b91ae086bbd2
site/components/SignIn/SignInForm.tsxhttps://github.com/coder/coder/pull/47/files#diff-1cbe9b77041934ab64b0029f915d9bc003f89fecb055b2fff3729fcb736b9287
View file https://github.com/coder/coder/blob/61af313fd1b533c705dcbe7f39a5426ff7bcd6e6/site/components/SignIn/SignInForm.tsx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/coder/coder/pull/47/{{ revealButtonHref }}
https://github.com/coder/coder/pull/47/files#diff-1cbe9b77041934ab64b0029f915d9bc003f89fecb055b2fff3729fcb736b9287
https://github.com/coder/coder/pull/47/files#diff-1cbe9b77041934ab64b0029f915d9bc003f89fecb055b2fff3729fcb736b9287
site/contexts/UserContext.tsxhttps://github.com/coder/coder/pull/47/files#diff-34932539f99928fc852f6a604bc265fda6e783e696acfa37a19790d763c9fce8
View file https://github.com/coder/coder/blob/61af313fd1b533c705dcbe7f39a5426ff7bcd6e6/site/contexts/UserContext.tsx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/coder/coder/pull/47/{{ revealButtonHref }}
https://github.com/coder/coder/pull/47/files#diff-34932539f99928fc852f6a604bc265fda6e783e696acfa37a19790d763c9fce8
https://github.com/coder/coder/pull/47/files#diff-34932539f99928fc852f6a604bc265fda6e783e696acfa37a19790d763c9fce8
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.