Skip to content

chore(staticcheck): resolve SA1019 in libvirt and generated protobuf#148

Open
jackthepunished wants to merge 2 commits intopoyrazK:mainfrom
jackthepunished:chore/staticcheck-cleanup-main
Open

chore(staticcheck): resolve SA1019 in libvirt and generated protobuf#148
jackthepunished wants to merge 2 commits intopoyrazK:mainfrom
jackthepunished:chore/staticcheck-cleanup-main

Conversation

@jackthepunished
Copy link
Copy Markdown
Contributor

@jackthepunished jackthepunished commented Apr 14, 2026

Summary

  • migrate deprecated libvirt constructor usage to NewWithDialer with a local unix dialer
  • suppress generated protobuf SA1019 deprecation warnings with a file-level staticcheck ignore

Validation

  • staticcheck ./...

Scoped staticcheck cleanup against main.

Copilot AI review requested due to automatic review settings April 14, 2026 12:17
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

Warning

Rate limit exceeded

@jackthepunished has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes and 28 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 51 minutes and 28 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e37532f8-c62a-4830-91e6-fe5ea669ea71

📥 Commits

Reviewing files that changed from the base of the PR and between 64dfd86 and 016fd33.

📒 Files selected for processing (1)
  • .github/workflows/benchmarks.yml
📝 Walkthrough

Walkthrough

The libvirt client initialization in the adapter is refactored to use a custom Unix-socket dialer with timeout support instead of pre-dialing a connection. The initial connection is now explicitly closed, delegating socket management to the libvirt client through libvirt.NewWithDialer(...).

Changes

Cohort / File(s) Summary
Libvirt Connection Initialization
internal/repositories/libvirt/adapter.go
Replaced libvirt.New(c) pattern with libvirt.NewWithDialer(...) using a custom libvirtUnixDialer. Initial connection is now explicitly closed before client creation, shifting socket lifecycle control to the client.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A socket once pre-dialed with care,
Now delegated through the air,
The dialer takes the reins with grace,
Each timeout finds its perfect place,
Connection flows with purpose true,
The adapter's dance is fresh and new! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the primary objective: resolving SA1019 deprecation warnings from staticcheck in libvirt and protobuf code through a migration to a new constructor approach.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to clean up Staticcheck SA1019 deprecation warnings by updating libvirt client construction and suppressing SA1019 in generated protobuf output.

Changes:

  • Switch libvirt adapter initialization from the deprecated libvirt.New(conn) pattern to libvirt.NewWithDialer(...) using a custom UNIX dialer.
  • Add a file-level Staticcheck ignore directive for SA1019 in a generated *.pb.go protobuf file.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/repositories/libvirt/adapter.go Replaces deprecated libvirt constructor usage with a dialer-based client initialization.
internal/autoscaler/protos/externalgrpc.pb.go Adds a file-level Staticcheck SA1019 suppression comment to generated protobuf code.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +125 to +126
_ = c.Close()
l := libvirt.NewWithDialer(&libvirtUnixDialer{uri: uri, timeout: 2 * time.Second})
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

NewLibvirtAdapter now opens a UNIX socket connection (c) only to close it immediately before creating the libvirt client via NewWithDialer. This creates an extra connection attempt at startup and duplicates the timeout value in multiple places. Consider removing the eager DialTimeout/Close() (or moving the system/session fallback selection into the dialer) and centralizing the timeout into a constant to avoid divergence.

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +23
//lint:file-ignore SA1019 Generated protobuf compatibility shims may reference deprecated APIs.

Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

This file is marked as generated (DO NOT EDIT), but the PR adds a linter directive inside it. That change will be lost the next time protobufs are regenerated and can create recurring diff churn. Prefer suppressing SA1019 for generated *.pb.go under internal/autoscaler/protos/ via .golangci.yml (issues.exclude-rules / linters-settings.staticcheck checks) rather than editing generated output.

Suggested change
//lint:file-ignore SA1019 Generated protobuf compatibility shims may reference deprecated APIs.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/repositories/libvirt/adapter.go`:
- Line 125: The probe socket Close() call currently discards any error with “_ =
c.Close()”; change this to capture the returned error from c.Close() (e.g., err
:= c.Close()) and handle it instead of ignoring it — at minimum call the
adapter's logger (or standard log) to record the failure (e.g., logger.Errorf /
log.Printf with context like "probe socket close failed") and, if appropriate
for the surrounding function (e.g., in the adapter setup/cleanup code where c is
closed), propagate the error or wrap it before returning so init-time socket
issues are not lost.
- Around line 25-39: The call to c.Close() (the probe connection close) is
silently ignoring its error; change the code that currently does `_ = c.Close()`
to explicitly handle the returned error from Close() (e.g., capture err :=
c.Close() and either log it via your logger or return/wrap it so callers can act
on it) or move the close into a small helper (e.g., closeConn(conn) that
documents best-effort cleanup and logs a non-nil error) so the intent is
explicit; additionally consider replacing the custom libvirtUnixDialer type and
its Dial() implementation with the upstream dialers.NewLocal(...) and its
WithSocket/WithLocalTimeout options to remove the custom Dialer implementation
if you prefer the upstream API.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7eb4858a-0dab-42a7-b684-8794b1b1d76e

📥 Commits

Reviewing files that changed from the base of the PR and between dbdf3fe and 64dfd86.

⛔ Files ignored due to path filters (1)
  • internal/autoscaler/protos/externalgrpc.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (1)
  • internal/repositories/libvirt/adapter.go

Comment on lines +25 to +39
libvirtsocket "github.com/digitalocean/go-libvirt/socket"
"github.com/google/uuid"
"github.com/poyrazk/thecloud/internal/core/ports"
)

type libvirtUnixDialer struct {
uri string
timeout time.Duration
}

var _ libvirtsocket.Dialer = (*libvirtUnixDialer)(nil)

func (d *libvirtUnixDialer) Dial() (net.Conn, error) {
return net.DialTimeout("unix", d.uri, d.timeout)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Pinned go-libvirt dependency entries:"
rg -n --no-heading 'github.com/digitalocean/go-libvirt' go.mod go.sum

echo
echo "New libvirt APIs referenced by this patch:"
sed -n '20,140p' internal/repositories/libvirt/adapter.go | rg -n 'NewWithDialer|go-libvirt/socket'

Repository: poyrazK/thecloud

Length of output: 636


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify the exact pinned version
echo "=== Pinned go-libvirt version ==="
rg 'github.com/digitalocean/go-libvirt' go.mod | head -1

# Get the full context around lines 120-130 to see the silent Close() issue
echo ""
echo "=== Code around line 125-126 (silent failure context) ==="
sed -n '115,135p' internal/repositories/libvirt/adapter.go

# Search for all usages of libvirtUnixDialer to understand its scope
echo ""
echo "=== All references to libvirtUnixDialer ==="
rg -n 'libvirtUnixDialer' internal/repositories/libvirt/

# Check imports in the file
echo ""
echo "=== Current imports in adapter.go ==="
sed -n '1,35p' internal/repositories/libvirt/adapter.go

Repository: poyrazK/thecloud

Length of output: 2113


🌐 Web query:

go-libvirt socket.Dialer dialers.NewLocal WithSocket WithLocalTimeout API documentation

💡 Result:

The go-libvirt library (github.com/digitalocean/go-libvirt) provides a socket dialing API in the socket/dialers subpackage for connecting to libvirt daemons via UNIX sockets, TCP, TLS, SSH, etc. Key components: - socket.Dialer is the interface: type Dialer interface { Dial (net.Conn, error) } - dialers.NewLocal(opts ...LocalOption) creates a local (UNIX socket) dialer. It is the default for connecting to a locally running libvirt socket. - dialers.WithSocket(socket string) LocalOption: Specifies a custom UNIX socket path (e.g., dialers.NewLocal(dialers.WithSocket("/var/run/libvirt/virtqemud-sock")) for modular daemons). - dialers.WithLocalTimeout(timeout time.Duration) LocalOption: Sets the dial timeout for the local connection. Usage example from sources: dialer := dialers.NewLocal(dialers.WithSocket("/path/to/socket"), dialers.WithLocalTimeout(5*time.Second)) lv := libvirt.NewWithDialer(dialer) lv.Connect This is used internally by libvirt.ConnectToURI for "unix" transports, parsing ?socket= from the URI. Official documentation: pkg.go.dev/github.com/digitalocean/go-libvirt/socket/dialers (updated Feb 2026). Source code examples in github.com/digitalocean/go-libvirt/tree/main/socket/dialers and connect_uri.go.

Citations:


Handle the error from Close() at line 125; do not silently ignore it.

The probe connection must have its error handled explicitly. Currently _ = c.Close() violates the guideline prohibiting silent failures via blank identifier assignment.

If the error is intentionally ignored (e.g., best-effort cleanup before reconnection), capture it explicitly or wrap the close in a helper that documents the intent.


Optional: Replace the custom libvirtUnixDialer with the upstream local dialer.

The pinned go-libvirt version (v0.0.0-20260106181248-56be673cd6a5) includes dialers.NewLocal(...) and its options (WithSocket, WithLocalTimeout), which provide the same functionality more idiomatically:

Suggested refactoring
-	libvirtsocket "github.com/digitalocean/go-libvirt/socket"
+	"github.com/digitalocean/go-libvirt/socket/dialers"
@@
-type libvirtUnixDialer struct {
-	uri     string
-	timeout time.Duration
-}
-
-var _ libvirtsocket.Dialer = (*libvirtUnixDialer)(nil)
-
-func (d *libvirtUnixDialer) Dial() (net.Conn, error) {
-	return net.DialTimeout("unix", d.uri, d.timeout)
-}
@@
-	l := libvirt.NewWithDialer(&libvirtUnixDialer{uri: uri, timeout: 2 * time.Second})
+	l := libvirt.NewWithDialer(dialers.NewLocal(
+		dialers.WithSocket(uri),
+		dialers.WithLocalTimeout(2*time.Second),
+	))

This removes the custom type and aligns with the upstream library's design.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/repositories/libvirt/adapter.go` around lines 25 - 39, The call to
c.Close() (the probe connection close) is silently ignoring its error; change
the code that currently does `_ = c.Close()` to explicitly handle the returned
error from Close() (e.g., capture err := c.Close() and either log it via your
logger or return/wrap it so callers can act on it) or move the close into a
small helper (e.g., closeConn(conn) that documents best-effort cleanup and logs
a non-nil error) so the intent is explicit; additionally consider replacing the
custom libvirtUnixDialer type and its Dial() implementation with the upstream
dialers.NewLocal(...) and its WithSocket/WithLocalTimeout options to remove the
custom Dialer implementation if you prefer the upstream API.


//nolint:staticcheck
l := libvirt.New(c)
_ = c.Close()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Don't silently drop the probe socket Close() failure.

Line 125 discards the only signal that the preflight socket cleanup failed. At least log it so init-time socket issues do not disappear during adapter setup.

🛠️ Suggested fix
-	_ = c.Close()
+	if err := c.Close(); err != nil {
+		logger.Warn("failed to close preflight libvirt socket", "uri", uri, "error", err)
+	}

As per coding guidelines, "Do not use silent failures - avoid blank identifier assignment like _ = someFunc()".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_ = c.Close()
if err := c.Close(); err != nil {
logger.Warn("failed to close preflight libvirt socket", "uri", uri, "error", err)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/repositories/libvirt/adapter.go` at line 125, The probe socket
Close() call currently discards any error with “_ = c.Close()”; change this to
capture the returned error from c.Close() (e.g., err := c.Close()) and handle it
instead of ignoring it — at minimum call the adapter's logger (or standard log)
to record the failure (e.g., logger.Errorf / log.Printf with context like "probe
socket close failed") and, if appropriate for the surrounding function (e.g., in
the adapter setup/cleanup code where c is closed), propagate the error or wrap
it before returning so init-time socket issues are not lost.

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