Skip to content

Fix two latent scamp-go bugs: announce-parse panic + Send error swallow#44

Open
riccardo-perotti wants to merge 1 commit into
masterfrom
rp.ROP-9250.fix-scamp-go-bugs
Open

Fix two latent scamp-go bugs: announce-parse panic + Send error swallow#44
riccardo-perotti wants to merge 1 commit into
masterfrom
rp.ROP-9250.fix-scamp-go-bugs

Conversation

@riccardo-perotti

Copy link
Copy Markdown
Contributor

Both bugs were uncovered during the golangci-lint rollout (dead-assignment lint hits that were masking pre-existing bugs). Filed as ROP-9250.

Bug 1 — newServiceProxy panics on malformed announce data

serviceproxy.go: after unmarshaling the announce, classRecords[0..7] and (per action) actionsRawMessages[0..1] were indexed with no length check — short/malformed discovery data → index-out-of-range panic. Added two length guards (classRecords < 8, actionsRawMessages < 2) that return a clean error instead. No behavior change for valid announces.

Bug 2 — Connection.Send silently swallows write errors on a dead conn

connection.go: on "use of closed connection" / "broken pipe" write errors, the loop breaked and Send returned nilsilent message loss. Now returns a new ErrConnectionClosed sentinel (wrapping the underlying error) so callers can detect it and reconnect/retry. Also early-returns on a known-closed connection instead of writing anyway.

⚠️ Behavior change — Send now returns an error on dead-conn writes

Previously Send returned nil in these cases. All four in-repo callers already check the error and handle it well, so this is strictly an improvement:

  • requester.go — retries (was: thought it sent, then hung until response-timeout) ✅
  • service.go — closes the dead client ✅
  • client.go / action_options.go — propagate / log ✅

Callers wanting to special-case it can use errors.Is(err, scamp.ErrConnectionClosed).

Verification

go build / go vet / go test all pass; golangci-lint (v2.12.2/go1.26) 0 issues.

🤖 Generated with Claude Code

Both surfaced during the golangci-lint rollout (dead assignments that hid
pre-existing bugs).

Bug 1 — newServiceProxy (serviceproxy.go): malformed/short announce data
caused index-out-of-range panics (classRecords[0..7] and
actionsRawMessages[0..1] were indexed with no length check). Add length
guards that return a clean error instead of panicking.

Bug 2 — Connection.Send (connection.go): on "use of closed connection" /
"broken pipe" write errors the loop broke and Send returned nil, silently
losing the message. Propagate a new ErrConnectionClosed sentinel so callers
can detect the failure and reconnect/retry. Also early-return on a
known-closed connection instead of writing anyway.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@schellj schellj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Silent message loss is pretty bad.

Both fixes look good.

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