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

Fix race-y bug in db.server.ts #860

Merged
merged 1 commit into from
Oct 1, 2024
Merged

Fix race-y bug in db.server.ts #860

merged 1 commit into from
Oct 1, 2024

Conversation

surma
Copy link
Member

@surma surma commented Oct 1, 2024

In the old code, two database connections get created in dev mode, which I think is not intentional.

Specifically:

  1. On first load, the local prisma variable gets initialized to a new connection (as global.prisma is unset).
  2. Since we are in dev mode, and global.primsa is not set, global.prisma gets initialized to yet another, fresh connection.
  3. The first of these two connections gets exported and used.
  4. For later HMR reloads, the 2nd connection is taken from global.prisma, means we have to DB connections being used in parallel.

This PR moves the global check to after the dev mode check.

@surma surma requested a review from a team as a code owner October 1, 2024 11:33
@surma surma requested review from paulomarg and byrichardpowell and removed request for a team October 1, 2024 11:33
Copy link
Contributor

@paulomarg paulomarg left a comment

Choose a reason for hiding this comment

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

Created an app and it works normally, thanks!

@surma surma merged commit 2aa311b into main Oct 1, 2024
5 checks passed
@surma surma deleted the surma-patch-1 branch October 1, 2024 13:04
github-actions bot pushed a commit that referenced this pull request Oct 1, 2024
Fix race-y bug in db.server.ts
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