Add client cleanup to Hyperdrive examples#28121
Conversation
… code examples Address the inconsistency where MySQL examples included ctx.waitUntil(connection.end()) but all PostgreSQL examples (node-postgres, postgres.js, Drizzle, Prisma, Timescale tutorial) omitted client cleanup entirely. This adds: - ctx.waitUntil(client.end()) to all PostgreSQL code examples - ctx.waitUntil(connection.end()) to MySQL Drizzle ORM example - ctx.waitUntil(prisma.$disconnect()) to Prisma ORM example - A new 'Cleaning up client connections' section in connection-lifecycle.mdx explaining the best practice and clarifying that .end() only closes the local client, not the Hyperdrive-managed pool connection - Consistent comments across all examples explaining that Hyperdrive keeps the underlying database connection open in its pool for reuse - Updated step-by-step explanations in get-started.mdx for both PG and MySQL Also fixes pre-existing bugs: - Missing 'return' in node-postgres partial catch block - Missing error response in mysql2 partial catch block - Changed mysql2 Drizzle ORM import from 'mysql2' to 'mysql2/promise' for correct Promise-based .end() behavior Closes #19988
|
This PR requires additional review attention because it affects the following areas: PartialsThis PR updates partial files, which are pieces of content used across multiple files in our Render component.
|
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
|
/bonk resolve the conflicts and re-review |
|
To https://github.com/cloudflare/cloudflare-docs |
|
Bonk workflow failed. Check the logs for details. |
|
/bonk re-review again. Fix any merge markers. Make sure all code examples are fixed. |
…e and missing cleanup in index.mdx PostgreSQL example
|
Done. Here's a summary of the review and fixes: Review ResultsNo merge conflict markers found in any of the 10 changed files. Two code example bugs found and fixed (both caused by the merge with PR #28119 which changed Postgres examples from
All other 8 files are correct - the cleanup calls, comments, error handling fixes, and |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
fatal: couldn't find remote ref opencode/issue27109-20260205212545 |
|
Bonk workflow failed. Check the logs for details. |
Here's a summary of all changes made:
Validation
The issue author is partially correct. The claim that missing
.end()calls leak database connections is not quite accurate -- the connection lifecycle docs confirm that Workers automatically garbage collect client connections after each invocation, and Hyperdrive manages the origin pool independently. However, explicitly calling.end()viactx.waitUntil()is still best practice for clean teardown, and the inconsistency between MySQL examples (which had it) and PostgreSQL examples (which didn't) was genuinely confusing.Changes Made (10 files, 110 insertions, 18 deletions)
Core fix: Added
ctx.waitUntil(client.end())to all code examplesget-started.mdxctx.waitUntil(sql.end())to PostgreSQL example; improved MySQL comment consistencyuse-node-postgres-to-make-query.mdxctx.waitUntil(client.end())use-postgres-js-to-make-query.mdxctx.waitUntil(sql.end())index.mdxtimescale tutorialctx.waitUntil(client.end())to both POST and GET routesdrizzle-orm.mdx(Postgres)ctx.waitUntil(sql.end())drizzle-orm.mdx(MySQL)ctx.waitUntil(connection.end()), fixed import tomysql2/promiseprisma-orm.mdxctx.waitUntil(prisma.$disconnect())Key documentation improvement
connection-lifecycle.mdx: Added a new "Cleaning up client connections" section with:.end()is best practice.end()only closes the local client -- not the pooled origin connectionConsistent commenting pattern
All examples now use consistent comments explaining:
Pre-existing bug fixes (found during review)
use-node-postgres-to-make-query.mdx: Missingreturnbeforenew Response(...)in catch blockuse-mysql2-to-make-query.mdx: Missing error response return in catch blockdrizzle-orm.mdx(MySQL): Import changed from"mysql2"to"mysql2/promise"for correct Promise-based.end()behaviorCloses #27109
github run