Skip to content

Fix timeout and panic-recovery bugs in connection processing#744

Open
Seanstoppable wants to merge 1 commit into
zmap:masterfrom
Seanstoppable:ssmith/fix-timeout-bugs
Open

Fix timeout and panic-recovery bugs in connection processing#744
Seanstoppable wants to merge 1 commit into
zmap:masterfrom
Seanstoppable:ssmith/fix-timeout-bugs

Conversation

@Seanstoppable

@Seanstoppable Seanstoppable commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Three related correctness fixes in processing.go, surfaced by AI code review.

1. TCP dialer drops the per-target timeout (High)

After dialing, the connection's context was reset to the bare parent context:

castConn.ctx = ctx

This discarded the SessionTimeout (target timeout) deadline that NewTimeoutConnection had installed, so checkContext() no longer enforced the target timeout, and the prior cancel func was leaked. Now we cancel the previous context and re-root at the parent while preserving SessionTimeout.

2. TLS handshake timeout gated on the wrong flag (Medium)

The handshake timeout block was gated on baseFlags.ConnectTimeout but applied tlsFlags.TLSHandshakeTimeout. With ConnectTimeout=0 the handshake timeout was disabled entirely; with ConnectTimeout>0 and TLSHandshakeTimeout=0 it applied an already-expired deadline. Now gated on TLSHandshakeTimeout > 0.

3. Scanner panic recovery returns a nil Grab (High)

grabTarget recovered scanner panics in a deferred function, but with an unnamed *Grab return this unwound the function and returned nil, discarding all results (caller then encodes a nil grab). The recovery now runs inside a per-scanner closure, so the panic is recorded as an error result and BuildGrabFromInputResponse is still reached.

Three related correctness fixes in processing.go:

- TCP dialer: re-rooting the connection context at the main context dropped
  the per-target SessionTimeout (and leaked the previous cancel func), so the
  target timeout was no longer enforced after the dial. Preserve SessionTimeout
  and cancel the prior context.

- TLS wrapper: the handshake timeout block was gated on ConnectTimeout but
  applied TLSHandshakeTimeout. This disabled the handshake timeout when
  ConnectTimeout was 0, and could apply a zero (already-expired) deadline.
  Gate on TLSHandshakeTimeout instead.

- grabTarget: recovering from a scanner panic in a deferred function unwound
  grabTarget and returned a nil *Grab, discarding all results. Recover inside
  a per-scanner closure so the panic is recorded and BuildGrabFromInputResponse
  is still reached.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Seanstoppable Seanstoppable marked this pull request as ready for review June 22, 2026 19:39
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.

1 participant