Repository navigation
fix: remove stale COSI socket before binding - #8
Conversation
|
Warning Review limit reached
More reviews will be available in 50 minutes and 27 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR adds graceful handling of stale Unix domain sockets in the COSI driver startup. A new ChangesStale Socket Cleanup
🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a self-healing mechanism to clean up stale COSI Unix domain sockets on startup, preventing CrashLoopBackOff issues when the driver restarts after a non-graceful exit. It also replaces deprecated ioutil.ReadFile with os.ReadFile and adds comprehensive unit tests for the socket cleanup logic. The reviewer suggests improving the robustness of the socket cleanup function by separating the URL parsing error check from the scheme check and explicitly checking for an empty path before calling os.Stat.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| u, err := url.Parse(endpoint) | ||
| if err != nil || u.Scheme != "unix" { | ||
| return nil | ||
| } | ||
| path := u.Path | ||
|
|
||
| fi, err := os.Stat(path) |
There was a problem hiding this comment.
For better readability, safety, and defensive programming, we should:
- Separate the error check from the scheme check to avoid any potential nil-pointer dereference concerns if the condition is refactored in the future.
- Add an explicit check for an empty
pathto avoid callingos.Stat("")unnecessarily, which would otherwise perform a redundant system call and rely on OS-specific behavior for empty paths.
| u, err := url.Parse(endpoint) | |
| if err != nil || u.Scheme != "unix" { | |
| return nil | |
| } | |
| path := u.Path | |
| fi, err := os.Stat(path) | |
| u, err := url.Parse(endpoint) | |
| if err != nil { | |
| return nil | |
| } | |
| if u.Scheme != "unix" { | |
| return nil | |
| } | |
| path := u.Path | |
| if path == "" { | |
| return nil | |
| } | |
| fi, err := os.Stat(path) |
There was a problem hiding this comment.
Applied in 60f5672 — split the url.Parse error check from the scheme check and added an explicit empty-path guard before os.Stat (skips a redundant os.Stat("")). Also added a unix:// no-path unit test. Thanks!
There was a problem hiding this comment.
🧹 Nitpick comments (3)
cmd/seaweedfs-cosi-driver/main_test.go (1)
30-30: 💤 Low value
noctx:net.Listenin tests is flagged by golangci-lint.These calls are appropriate for creating real unix sockets in tests, but the static analyzer reports
noctxerrors. If CI enforces this linter, switch to(&net.ListenConfig{}).Listen(ctx, "unix", sock)or exclude_test.gofiles from thenoctxrule. See the.golangciconfig verification requested onmain.go.Also applies to: 55-55, 107-107
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/seaweedfs-cosi-driver/main_test.go` at line 30, Replace direct net.Listen("unix", sock) calls in the test file with context-aware ListenConfig to satisfy golangci-lint noctx: create a context (e.g., ctx := context.Background() or a cancellable/timeout context) and call (&net.ListenConfig{}).Listen(ctx, "unix", sock) instead, and add the context import; alternatively, if you prefer lint config changes, exclude _test.go from the noctx rule in .golangci.yml. Update all occurrences of net.Listen in this file (the three test call sites) and their imports accordingly.cmd/seaweedfs-cosi-driver/main.go (2)
129-134: 💤 Low value
noctx: replacenet.DialTimeoutwith context-based(*net.Dialer).DialContext
net.DialTimeoutis still supported (not deprecated), but thenoctxrule expects the context-aware dialing API.♻️ Optional: context-aware dial
- if c, err := net.DialTimeout("unix", path, 200*time.Millisecond); err == nil { + ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) + defer cancel() + var d net.Dialer + if c, err := d.DialContext(ctx, "unix", path); err == nil { // A live listener is still bound — leave it. The bind that follows will // surface the real "address already in use" if another instance runs. _ = c.Close() return nil }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/seaweedfs-cosi-driver/main.go` around lines 129 - 134, Replace the blocking call to net.DialTimeout with a context-aware dial: create a context with timeout (e.g., ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) and defer cancel()) and call (&net.Dialer{}).DialContext(ctx, "unix", path) instead of net.DialTimeout; keep the existing nil-check and _ = c.Close()/return nil logic unchanged so a live listener still short-circuits the bind attempt. Ensure you import context if not already present and preserve the 200*time.Millisecond timeout value.
111-116: 💤 Low value
removeStaleSocket: document the intentionalnilon malformed unix endpoints (CI likely won’t flagnilerr)
url.Parseerror being a no-op is reasonable, and the||preserves safety foru.Scheme. This repo’s CI runs golangci-lint via pre-commit (v2.10.1) without a.golangci.*config, andnilerrisn’t enabled by default in the standard preset—so the code should not surface asnilerrin this setup unless CI uses an explicit preset/config that enables it. For readability/resilience, split the parse-error vs non-unixchecks and add a brief comment; avoid//nolint:nilerrunlessnilerris actually active.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/seaweedfs-cosi-driver/main.go` around lines 111 - 116, In removeStaleSocket: split the combined check so we explicitly handle a parse error and non-unix schemes separately and add a short comment explaining that returning nil on a malformed or non-unix endpoint is intentional; e.g., call url.Parse(endpoint), if err != nil { /* malformed endpoint or not relevant to unix sockets: nothing to remove */ return nil }, then if u.Scheme != "unix" { return nil }, then proceed to use u.Path — do not add a //nolint:nilerr unless nilerr is enabled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cmd/seaweedfs-cosi-driver/main_test.go`:
- Line 30: Replace direct net.Listen("unix", sock) calls in the test file with
context-aware ListenConfig to satisfy golangci-lint noctx: create a context
(e.g., ctx := context.Background() or a cancellable/timeout context) and call
(&net.ListenConfig{}).Listen(ctx, "unix", sock) instead, and add the context
import; alternatively, if you prefer lint config changes, exclude _test.go from
the noctx rule in .golangci.yml. Update all occurrences of net.Listen in this
file (the three test call sites) and their imports accordingly.
In `@cmd/seaweedfs-cosi-driver/main.go`:
- Around line 129-134: Replace the blocking call to net.DialTimeout with a
context-aware dial: create a context with timeout (e.g., ctx, cancel :=
context.WithTimeout(context.Background(), 200*time.Millisecond) and defer
cancel()) and call (&net.Dialer{}).DialContext(ctx, "unix", path) instead of
net.DialTimeout; keep the existing nil-check and _ = c.Close()/return nil logic
unchanged so a live listener still short-circuits the bind attempt. Ensure you
import context if not already present and preserve the 200*time.Millisecond
timeout value.
- Around line 111-116: In removeStaleSocket: split the combined check so we
explicitly handle a parse error and non-unix schemes separately and add a short
comment explaining that returning nil on a malformed or non-unix endpoint is
intentional; e.g., call url.Parse(endpoint), if err != nil { /* malformed
endpoint or not relevant to unix sockets: nothing to remove */ return nil },
then if u.Scheme != "unix" { return nil }, then proceed to use u.Path — do not
add a //nolint:nilerr unless nilerr is enabled.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0885ab31-4189-4249-901e-5da6108481ba
📒 Files selected for processing (3)
.gitignorecmd/seaweedfs-cosi-driver/main.gocmd/seaweedfs-cosi-driver/main_test.go
A non-graceful driver exit (SIGKILL/OOM/panic) leaves the COSI unix socket
file behind — Go's net package only unlinks it on a graceful listener close.
The socket lives on an emptyDir shared with the sidecar that survives container
restarts, so the next net.Listen("unix", …) fails with EADDRINUSE and wedges
the pod in CrashLoopBackOff ("bind: address already in use"), recoverable only
by deleting the pod.
Remove a stale socket before starting the provisioner server so the driver
self-heals on restart. The endpoint is parsed with net/url (matching the path
the provisioner sidecar binds), and removal is guarded: it deletes only a path
that exists, is a socket, and has no live listener — never a regular file or a
socket that is still being served.
Assisted-By: Claude <[email protected]>
Signed-off-by: Aleksei Sviridkin <[email protected]>
f50a9d9 to
60f5672
Compare
## What this PR does Bumps the `seaweedfs-cosi-driver` image from `v0.3.0` to `v0.3.1`. `v0.3.1` ships the stale-socket self-heal fix. After a non-graceful exit (SIGKILL / OOM / panic) Go does not unlink the COSI unix socket, and because it lives on an `emptyDir` that survives container restarts, the next start failed with `bind: address already in use` and the `objectstorage-provisioner` wedged in `CrashLoopBackOff`. While it was down, `BucketClaim` reconciliation stopped and buckets were never provisioned — the COSI `Bucket` could even report `bucketReady: true` while no bucket existed. This is the CrashLoopBackOff reported in #2429. The driver now removes a leftover socket before binding (only when it exists, is a socket, and has no live listener), so the provisioner self-heals on restart. Upstream: seaweedfs/seaweedfs-cosi-driver#8 (merged), released in v0.3.1. Points at the upstream published multi-arch image (amd64 + arm64) — no vendoring needed. ### Release note ```release-note fix(seaweedfs): bump seaweedfs-cosi-driver to v0.3.1, which self-heals the object storage COSI provisioner from a CrashLoopBackOff caused by a stale unix socket ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Updated SeaweedFS cosi driver container image to a newer version. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Problem
The COSI gRPC socket (
unix:///var/lib/cosi/cosi.sockby default) is created on anemptyDirshared between the driver and the COSI sidecar. Go'snetpackage only unlinks a unix socket on a graceful listener close, so a non-graceful exit (SIGKILL / OOM / panic) leaves the socket file behind. TheemptyDirsurvives container restarts, so the next start fails to bind:A single transient crash then wedges the pod in a permanent
CrashLoopBackOff, recoverable only by deleting the pod, and object storage stays unusable in the meantime.This fix comes from Cozystack, a CNCF Sandbox project that ships
seaweedfs-cosi-driveras the COSI provisioner for its built-in S3 offering. It hits real users in production, so we are carrying the patch as a vendored fix in Cozystack and upstreaming it here so the whole driver community benefits. Tracked downstream in cozystack/cozystack#2429 (72 driver restarts observed on a single pod).Fix
Remove a stale socket before starting the provisioner server, so the driver self-heals on restart.
net/url— the same wayprovisioner.Runderives the bind path (url.Parse(addr).Path) — so the path removed is exactly the path that will be bound, including for non-default endpoints.os.ModeSocket), and has no live listener (a shortnet.DialTimeoutprobe). It never deletes a regular file/directory or a socket that is still being served.Tests
Adds
cmd/seaweedfs-cosi-driver/main_test.gocovering: stale socket removed, live socket kept, absent path no-op, regular file kept, non-unix endpoint ignored, and theurl.Pathparsing contract.go test,go vet,go build,gofmt, andgolangci-lintall pass locally.Summary by CodeRabbit
Bug Fixes
Tests