Skip to content

Document package connection lifetime - #682

Open
LeonidasZhak wants to merge 6 commits into
r-dbi:mainfrom
LeonidasZhak:codex/document-dbdisconnect-lifetime
Open

LeonidasZhak wants to merge 6 commits into
r-dbi:mainfrom
LeonidasZhak:codex/document-dbdisconnect-lifetime

Conversation

@LeonidasZhak

@LeonidasZhak LeonidasZhak commented Jun 5, 2026 •

Copy link
Copy Markdown

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 = TRUE and .onUnload() paths, and test that unload cleanup safely disconnects an open singleton connection. Repeated unload cleanup is covered too.

Tests

  • Focused devtools::test(filter = "dbDisconnect") and full devtools::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 . and git diff --check — pass.

Scope

No DBI API, backend methods, or connection dispatch behavior changed.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Formatting suggestions available

A 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.patch

Repo owners can also apply the patch automatically. Click the button to jump to the comment box, then post:

/apply-patch

Apply patch

Method 2: View the patch

Click to see the patch contents
diff --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.

@LeonidasZhak

LeonidasZhak commented Jun 20, 2026 •

Copy link
Copy Markdown
Author

Summary

I rechecked this PR locally today and did not make further code changes.

Thanks to maintainers

Thanks again for the guidance on documenting this package-level connection-lifetime pattern.

Issue or motivation

My 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 cause

At the moment, every visible PR check is successful except rcc: windows-latest (4.5) from run 27012171136. That job fails during the workflow install/setup stage, so the aggregate rcc status for commit 22980a7e remains failing. The branch is not behind main, and the current head already includes the generated man/dbDisconnect.Rd alignment for this doc addition.

Change

No code changes today. I only rechecked the current head and confirmed that the Connection lifetime in packages section matches between R/dbDisconnect.R and man/dbDisconnect.Rd.

Tests

  • git diff --check
  • R CMD INSTALL .
  • R CMD build --no-build-vignettes .
  • _R_CHECK_FORCE_SUGGESTS_=false R CMD check --no-manual --ignore-vignettes --no-build-vignettes --no-tests DBI_1.3.0.9010.tar.gz

Scope

I 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.

@LeonidasZhak

Copy link
Copy Markdown
Author

Following up on my earlier CI note: the latest recorded run still fails at rcc: windows-latest (4.5) during the install step; the other jobs passed. The logs have expired, and rerunning requires repository admin rights. Could a maintainer retry it or confirm whether this is the Windows runner transition notice? The branch is unchanged since 22980a7.

@krlmlr krlmlr mentioned this pull request Nov 28, 2026
3 of 7 tasks
@krlmlr

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member

Thanks. See review in #781 (comment), need to do one more iteration here.

@krlmlr krlmlr mentioned this pull request Nov 29, 2026
15 of 22 tasks

This branch has not been deployed

No deployments
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