Skip to content

Commit 4a1c46d

Browse files
authored
fix: add nil check before writing to dest in handshake handle - LMN (#88)
2 parents a0a6801 + 5884308 commit 4a1c46d

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

internal/resources/hashrate/proxy/handler_first_connect.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,22 @@ func (p *HandlerFirstConnect) handleSource(ctx context.Context, msg i.MiningMess
7272
case *m.MiningExtranonceSubscribe:
7373
// Pass through extranonce subscription to pool
7474
p.proxy.logDebugf("forwarding mining.extranonce.subscribe from source")
75-
return nil, p.proxy.dest.Write(ctx, msgTyped)
75+
if p.proxy.dest != nil {
76+
return nil, p.proxy.dest.Write(ctx, msgTyped)
77+
}
78+
return nil, nil
7679

7780
case *m.MiningSubmit:
7881
return nil, fmt.Errorf("unexpected handshake message from source: %s", string(msg.Serialize()))
7982

8083
default:
8184
p.proxy.logWarnf("unknown handshake message from source: %s", string(msg.Serialize()))
82-
// todo: maybe just return message, so pipe will write it
83-
return nil, p.proxy.dest.Write(ctx, msgTyped)
85+
// Only forward if destination is initialized
86+
if p.proxy.dest != nil {
87+
return nil, p.proxy.dest.Write(ctx, msgTyped)
88+
}
89+
// Drop message if destination not ready
90+
return nil, nil
8491
}
8592
}
8693

0 commit comments

Comments
 (0)