Skip to content

Handle cleanup errors and enable errcheck - #11

Merged
kilo666mj merged 1 commit into
mainfrom
errcheck/enable
Sep 7, 2026
Merged

kilo666mj merged 1 commit into
mainfrom
errcheck/enable

Conversation

@kilo666mj

Copy link
Copy Markdown
Owner

Completes gatekit's entry in the ERRCHECK_BACKLOG.md rollout. 47 findings — 29 in production paths, 18 in tests. Measured with --max-same-issues=0 --max-issues-per-linter=0, so this is the complete backlog, not golangci-lint's first diagnostic page.

Production follows the pattern already established in gatehub. A new unexported store/cleanup.go provides closeError, closeWithError and rollbackTransaction, so row, statement, transaction and database cleanup joins onto a named error return instead of being dropped. A rollback after a successful commit still reports sql.ErrTxDone as the expected outcome rather than a failure. Open joins its unwind close failures onto the error that caused the unwind.

Two judgement calls worth review:

  • migrateLegacy keeps closing its rows explicitly before BeginTx rather than deferring. Reads and writes share the single writer connection (db.SetMaxOpenConns(1)), so holding the rows open until return would block the write it's about to make. Deferring here would have been the tidier-looking change and the wrong one.
  • The proxy logs its close error rather than returning it — a served connection has nowhere to return one — and treats an already-closed peer (net.ErrClosed) as the normal case, not a fault. This matches sshgate.

Tests assert store and database cleanup, since a failed close means the database didn't shut down cleanly and, in the two places a test reopens the file, invalidates everything the reopen then asserts. Test-server encode failures are asserted too: a fixture that fails to encode leaves the test checking a body it never sent. Only net.Pipe and unixgram listener teardown is marked best-effort with _ =.

No public API changes — the named returns don't alter any signature's type.

Verified locally: go build, go vet, gofmt -l, go test ./... and go test -race ./... all pass, and golangci-lint v2.13.2 reports 0 issues under the repository's own config with errcheck enabled.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kt6cL2BR1oWL7v6DtEgCCm

Completes gatekit's entry in the errcheck rollout: 47 findings, 29 in
production paths and 18 in tests.

Production paths follow the pattern already established in gatehub. A new
unexported store/cleanup.go provides closeError, closeWithError and
rollbackTransaction, so row, statement, transaction and database cleanup
joins onto a named error return instead of being dropped, and a rollback
after a successful commit still reports sql.ErrTxDone as the expected
outcome rather than a failure. Open now joins its unwind close failures onto
the error that caused the unwind.

migrateLegacy keeps closing its rows explicitly before BeginTx rather than
deferring: reads and writes share the single writer connection, so holding
the rows open until return would block the write it is about to make.

The proxy has nowhere to return a served connection's close error, so it
logs it, treating an already-closed peer as the normal case. sdnotify and
the control-plane HTTP client join theirs onto the returned error.

In tests, store and database cleanup is asserted, since a failed close means
the database did not shut down cleanly and, where a test reopens the file,
invalidates everything the reopen asserts. Test-server encode failures are
asserted too, because a fixture that fails to encode leaves the test
checking a body it never sent. Only net.Pipe and unixgram listener teardown
is marked best-effort with _ =.

go build, go vet, gofmt, go test and go test -race all pass, and
golangci-lint reports zero issues under the repository's own configuration.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kt6cL2BR1oWL7v6DtEgCCm
@kilo666mj
kilo666mj merged commit c5eaf1b into main Sep 7, 2026
5 checks passed
@kilo666mj
kilo666mj deleted the errcheck/enable branch September 7, 2026 09:44
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.

1 participant