From 72efee01cf37bf335ba82768a8b4f9ca94cd3e9b Mon Sep 17 00:00:00 2001 From: abs2023 Date: Tue, 10 Feb 2026 15:57:36 -0500 Subject: [PATCH] fix: add nil check before writing to dest in handshake handler 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 --- .../hashrate/proxy/handler_first_connect.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/resources/hashrate/proxy/handler_first_connect.go b/internal/resources/hashrate/proxy/handler_first_connect.go index 02d0533..3e2aed6 100644 --- a/internal/resources/hashrate/proxy/handler_first_connect.go +++ b/internal/resources/hashrate/proxy/handler_first_connect.go @@ -72,15 +72,22 @@ func (p *HandlerFirstConnect) handleSource(ctx context.Context, msg i.MiningMess case *m.MiningExtranonceSubscribe: // Pass through extranonce subscription to pool p.proxy.logDebugf("forwarding mining.extranonce.subscribe from source") - return nil, p.proxy.dest.Write(ctx, msgTyped) + if p.proxy.dest != nil { + return nil, p.proxy.dest.Write(ctx, msgTyped) + } + return nil, nil case *m.MiningSubmit: return nil, fmt.Errorf("unexpected handshake message from source: %s", string(msg.Serialize())) default: p.proxy.logWarnf("unknown handshake message from source: %s", string(msg.Serialize())) - // todo: maybe just return message, so pipe will write it - return nil, p.proxy.dest.Write(ctx, msgTyped) + // Only forward if destination is initialized + if p.proxy.dest != nil { + return nil, p.proxy.dest.Write(ctx, msgTyped) + } + // Drop message if destination not ready + return nil, nil } }