fix: add nil check before writing to dest in handshake handler#86
Merged
fix: add nil check before writing to dest in handshake handler#86
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_submitLoginfrom Ethereum miners connecting to Bitcoin proxy), the code attempts to forward the message viap.proxy.dest.Write(). However,p.proxy.destis nil during early handshake, causing panic atconn_dest.go:139viahandler_first_connect.go:83.Changes Made
Added defensive nil checks in
handler_first_connect.gobefore writing to dest:MiningExtranonceSubscribe case:
p.proxy.dest != nilbefore forwardingDefault case (unknown messages):
p.proxy.dest != nilbefore forwardingImpact
Evidence
Crash pattern:
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