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: remove outdated section about shutdown hooks with prisma #2797

Merged
merged 1 commit into from
Jul 13, 2023

Conversation

aqrln
Copy link
Contributor

@aqrln aqrln commented Jul 12, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Docs
  • Other... Please describe:

What is the current behavior?

Current Prisma guide needs to be updated as custom enableShutdownHooks method has not been necessary since Prisma 3, and now the example doesn't compile since Prisma 5.

This leads to confusion for users: prisma/prisma#20171
Release notes: https://github.com/prisma/prisma/releases/tag/5.0.0

What is the new behavior?

The outdated section is removed.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This section has not been relevant since the introduction of the library engine as the default in Prisma 3. Now, in Prisma 5, the code example does not compile anymore since the beforeExit event was removed from Prisma Client (except when generating the client with the binary engine type, which most users should not do unless they have good reasons).

Note that even in Prisma 2 or when switching to the binary engine, using beforeExit would've only been necessary to be able to run database queries in lifecycle hooks, and wouldn't be necessary otherwise. The justification for using beforeExit that was present in this section was not fully accurate because while the bug it refers to (prisma/prisma#3773) was fixed together with the introduction of beforeExit hook (which I believe led to the confusion), those were not strictly related changes.

This section has not been relevant since the introduction of the library
engine as the default in Prisma 3. Now, in Prisma 5, the code example
does not compile anymore since the `beforeExit` event was removed from
Prisma Client (except when generating the client with the binary engine
type, which most users should not do unless they have good reasons).

Note that even in Prisma 2 or when switching to the binary engine, using
`beforeExit` would've only been necessary to be able to run database
queries in lifecycle hooks, and wouldn't be necessary otherwise. The
justification for using `beforeExit` that was present in this section
was not fully accurate because while the bug it refers to
(prisma/prisma#3773) was fixed together with
the introduction of `beforeExit` hook (which I believe led to the
confusion), those were not strictly related changes.
}
```

> info **Note** The `onModuleInit` is optional — if you leave it out, Prisma will connect lazily on its first call to the database. We don't bother with `onModuleDestroy`, since Prisma has its own shutdown hooks where it will destroy the connection. For more info on `enableShutdownHooks`, please see [Issues with `enableShutdownHooks`](recipes/prisma#issues-with-enableshutdownhooks)
Copy link
Contributor Author

@aqrln aqrln Jul 12, 2023

Choose a reason for hiding this comment

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

We don't bother with onModuleDestroy, since Prisma has its own shutdown hooks where it will destroy the connection.

This was also a little inaccurate, at least since Prisma 3.

Prisma's own shutdown hooks in Prisma 2 (or in modern Prisma when using the binary engine) existed to kill the query engine process, but they didn't explicitly close the db connection. I'm not sure if the engine did that by catching the signal itself, but I can't seem to find that in the engines codebase.

In Prisma 3+, with library engine (a Node.js native addon), the only reason the internal shutdown hooks still existed was to maintain backward compatibility and keep the beforeExit event, but they haven't been doing anything beyond that.

If it's desired to close the connections gracefully rather than dropping them, it's still necessary to add an onModuleDestroy method with explicit $disconnect. I can do this in this PR if you'd prefer.

@kamilmysliwiec kamilmysliwiec merged commit 932d1f0 into nestjs:master Jul 13, 2023
@kamilmysliwiec
Copy link
Member

LGTM

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.

4 participants