Skip to content

fix: run libvirt Connect synchronously to prevent goroutine leak (#286)#491

Open
poyrazK wants to merge 1 commit intomainfrom
fix/libvirt-connect-goroutine-leak-286
Open

fix: run libvirt Connect synchronously to prevent goroutine leak (#286)#491
poyrazK wants to merge 1 commit intomainfrom
fix/libvirt-connect-goroutine-leak-286

Conversation

@poyrazK
Copy link
Copy Markdown
Owner

@poyrazK poyrazK commented May 7, 2026

Summary

Run r.conn.Connect() synchronously instead of in a goroutine.

Why:

  • r.conn.Connect() is a blocking C binding that cannot be cancelled
  • Goroutine pattern added complexity without benefit
  • If context fires during Connect(), the goroutine continued anyway
  • Now: context checked before starting; if cancelled, returns early

Changes:

  • Connect(): removed goroutine, added ctx check, run directly
  • ConnectToURI(): same pattern
  • Removed sync import (no longer needed)

Fixes #286

The r.conn.Connect() C binding is a blocking call that cannot be
interrupted by context cancellation. Running it in a goroutine added
complexity without benefit - if context fires during Connect(), the
goroutine continued until Connect() returned anyway.

Run Connect synchronously with context check before starting. This
eliminates goroutine leak while keeping the early-return behavior
when context is already cancelled.

Fixes #286
Copilot AI review requested due to automatic review settings May 7, 2026 18:42
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Warning

Rate limit exceeded

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

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ 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: 4a766406-c8bc-46bc-94cf-32277e40dfcb

📥 Commits

Reviewing files that changed from the base of the PR and between 5faabcc and cac8d98.

📒 Files selected for processing (1)
  • internal/repositories/libvirt/real_client.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/libvirt-connect-goroutine-leak-286

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

Libvirt Connect methods spawn goroutines with context leak potential at real_client.go:19,33

2 participants