Skip to content

Close dump resources on every return path - #5804

Merged
d3flex merged 2 commits into
rancher:mainfrom
kojah:add-gohawk-ci
Oct 14, 2026
Merged

d3flex merged 2 commits into
rancher:mainfrom
kojah:add-gohawk-ci

Conversation

@kojah

@kojah kojah commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Changes:

  • Extract metrics collection into its own helper to scope port-forward and HTTP response cleanup to a single loop iteration, instead of keeping them open through the entire archive operation.
  • Register tar and gzip writer cleanup immediately, so early errors won't leave either writer open.

Testing:

  • go test ./internal/cmd/cli/dump ./internal/content
  • go run github.com/kojah/gohawk@v0.3.0 ./...

Additional Information

I've added gohawk to the lint workflow alongside golangci-lint, reusing the existing checkout and Go setup. It's what found the issues in this PR, so feel free to keep it around if you find it useful :) if not, you're welcome to remove it from this PR.

Checklist

  • I have updated the documentation via a pull request in the fleet-product-docs repository.

@kojah
kojah requested a review from a team as a code owner September 17, 2026 18:31
Copilot AI lite review requested due to automatic review settings September 17, 2026 18:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tar writer is closed twice on the successful path, adding an unnecessary archive trailer.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR improves dump resource cleanup and adds gohawk validation to CI.

Changes:

  • Scopes metrics cleanup per service.
  • Adds archive writer cleanup for early returns.
  • Adds gohawk to CI with the required gzip-reader suppression.
File summaries
File Summary
internal/content/helpers.go Documents the intentional gzip-reader lifetime exception.
internal/cmd/cli/dump/dump.go Refactors metrics collection and archive writer cleanup; the tar writer is still closed twice on successful dumps.
.github/workflows/golangci-lint.yml Adds gohawk validation to CI.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/cmd/cli/dump/dump.go
@d3flex

d3flex commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

I added a commit to address the copilot's feedback and I removed the commit which adds gohawk in CI. I took a quick look in your repo and I think it is better to leave it for later.

But thanks a lot for yr PR and fixing that particular issue. appreciated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Early errors still leave the tar writer unclosed, and the advertised CI check is absent.

1 open finding
1 resolved since last review

🧠 Review effort: Lite

Comment thread internal/cmd/cli/dump/dump.go
w is still explicitly closed at lines 1004-1006, so this defer runs a second
time on every successful dump. Unlike gzip.Writer.Close, tar.Writer.Close is
not idempotent: each call writes another pair of end-of-archive blocks,
adding an unnecessary extra trailer to every archive.

Make the deferred cleanup explicitely so the tar writer is closed exactly once
and add an explicit check after gz.Close() for tgz.Close so an error can be
caught similar with gz and w.

Signed-off-by: Ioannis Bonatakis <ybonatakis@suse.com>
@d3flex
d3flex enabled auto-merge (rebase) October 14, 2026 11:33
@d3flex
d3flex merged commit 5b94ba0 into rancher:main Oct 14, 2026
23 checks passed
@d3flex d3flex changed the title Close dump resources on every return path and add gohawk to CI Close dump resources on every return path Oct 15, 2026
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.

3 participants