Skip to content

Comments

fix: add nil check before writing to dest in handshake handler#86

Merged
abs2023 merged 1 commit intodevfrom
fix/nil-dest-write-handshake
Feb 10, 2026
Merged

fix: add nil check before writing to dest in handshake handler#86
abs2023 merged 1 commit intodevfrom
fix/nil-dest-write-handshake

Conversation

@abs2023
Copy link
Contributor

@abs2023 abs2023 commented Feb 10, 2026

Summary

Fixes secondary crash discovered after PR #83 deployment. Adds defensive nil checks before attempting to write to destination during handshake phase.

Root Cause

After deploying PR #83 (which fixed the logging crash), a second nil pointer issue was discovered at 2026-02-10 20:56 UTC:

When miners send unexpected protocol messages before the destination connection is initialized (e.g., eth_submitLogin from Ethereum miners connecting to Bitcoin proxy), the code attempts to forward the message via p.proxy.dest.Write(). However, p.proxy.dest is nil during early handshake, causing panic at conn_dest.go:139 via handler_first_connect.go:83.

Changes Made

Added defensive nil checks in handler_first_connect.go before writing to dest:

  1. MiningExtranonceSubscribe case:

    • Check if p.proxy.dest != nil before forwarding
    • Return nil, nil if dest not ready (safe drop)
  2. Default case (unknown messages):

    • Check if p.proxy.dest != nil before forwarding
    • Return nil, nil if dest not ready (safe drop)
    • Updated comment to clarify behavior

Impact

Evidence

Crash pattern:

panic: runtime error: invalid memory address or nil pointer dereference  
[signal SIGSEGV: segmentation violation code=0x1 addr=0x110 pc=0x8feae6]
at conn_dest.go:139 via handler_first_connect.go:83

Trigger log (showing PR #83 logging fix working):

{"level":"warn","logger":"PRX","msg":"unknown handshake message from source: {\"id\":2,\"method\":\"eth_submitLogin\"...}",
"SrcAddr":"188.166.37.58:47284","DstAddr":"not-initialized","DstPort":"not-connected"}

The logging successfully showed "not-initialized" and "not-connected" (PR #83 fix working), but then crashed trying to forward the message.

Dependencies

Made with Cursor

Prevents panic when unknown messages arrive before destination is initialized.

Additional issue found after first fix deployment: when miners send
unexpected protocol messages (e.g. eth_submitLogin from Ethereum miners)
before the destination connection is established, the code attempted to
forward the message to p.proxy.dest.Write() which was nil, causing panic
at conn_dest.go:139.

This fix adds defensive nil checks in both the MiningExtranonceSubscribe
case and the default case before attempting to write to dest. Messages
arriving before dest initialization are now safely dropped.

Resolves second crash pattern discovered at 2026-02-10 20:56 UTC.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abs2023 abs2023 merged commit fb90d90 into dev Feb 10, 2026
2 checks passed
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