Repository navigation
Document package connection lifetime - #682
LeonidasZhak wants to merge 6 commits into
Conversation
Formatting suggestions availableA patch file with formatting suggestions has been generated. You can apply it using one of these methods: Method 1: Apply via gh CLI# Download and apply the patch directly
gh run download 27011862185 --repo r-dbi/DBI --name changes-patch && patch -p1 < changes.patch && rm changes.patchRepo owners can also apply the patch automatically. Click the button to jump to the comment box, then post: Method 2: View the patchClick to see the patch contentsdiff --git a/man/dbDisconnect.Rd b/man/dbDisconnect.Rd
index 9bbc389..b4f3377 100644
--- a/man/dbDisconnect.Rd
+++ b/man/dbDisconnect.Rd
@@ -21,6 +21,15 @@ resources (e.g., memory, sockets).
\Sexpr[results=rd,stage=render]{DBI:::methods_as_rd("dbDisconnect")}
}
+\section{Connection lifetime in packages}{
+
+For package-level connection reuse, consider delegating connection lifetime
+management to the pool package. If a package manages a long-lived connection
+itself, any finalizer that calls \code{dbDisconnect()} should keep the connection
+object reachable until the finalizer runs, and should check \code{\link[=dbIsValid]{dbIsValid()}}
+before disconnecting.
+}
+
\section{Failure modes}{
@@ -31,15 +40,6 @@ At least one warning is issued immediately when calling \code{dbDisconnect()} on
already disconnected
or invalid connection.
-}
-\section{Connection lifetime in packages}{
-
-For package-level connection reuse, consider delegating connection lifetime
-management to the pool package. If a package manages a long-lived connection
-itself, any finalizer that calls \code{dbDisconnect()} should keep the connection
-object reachable until the finalizer runs, and should check \code{\link[=dbIsValid]{dbIsValid()}}
-before disconnecting.
-
}
\examples{This comment was automatically generated by the commit-suggester workflow. |
SummaryI rechecked this PR locally today and did not make further code changes. Thanks to maintainersThanks again for the guidance on documenting this package-level connection-lifetime pattern. Issue or motivationMy last note could read as if the PR were fully green. It is not: the branch is locally validated, but the PR is still blocked by one upstream CI failure. Root causeAt the moment, every visible PR check is successful except ChangeNo code changes today. I only rechecked the current head and confirmed that the Tests
ScopeI did not change the wording beyond the existing PR, did not touch workflows, and did not push a new commit. I also cannot rerun the upstream failed job from a fork because that requires repository admin rights. |
|
Following up on my earlier CI note: the latest recorded run still fails at |
|
Thanks. See review in #781 (comment), need to do one more iteration here. |
Summary
Clarify singleton connection cleanup and test package unload behavior.
Thanks to maintainers
Thanks for the concrete finalizer example and the focused review.
Issue or motivation
Addresses #532 by documenting cleanup for short-lived and package-managed connections.
Root cause
A package-level environment remains reachable while its namespace is loaded, so its finalizer does not run during normal operation. The documentation needed to state when the finalizer runs and how unload cleanup complements it.
Change
Explain the
onexit = TRUEand.onUnload()paths, and test that unload cleanup safely disconnects an open singleton connection. Repeated unload cleanup is covered too.Tests
devtools::test(filter = "dbDisconnect")and fulldevtools::test()— pass; 58 existing skips for optional backend or feature requirements.R CMD build --no-manual— pass.R CMD check --as-cran --no-manual --no-multiarch— Status: OK. Remote CRAN incoming checks were disabled after the index request failed with SSL; the vignette rebuild used a local copy of its existing lifecycle badge.air format --check .andgit diff --check— pass.Scope
No DBI API, backend methods, or connection dispatch behavior changed.