Commit 04c4d0a
authored
fix: handle mining.extranonce.subscribe and prevent nil pointer crash (#83)
## Summary
Fixes crash loop caused by new miners sending
`mining.extranonce.subscribe` messages during handshake phase.
## Root Cause
New miners added to seller node on 2026-02-10 send the
`mining.extranonce.subscribe` Stratum extension message during initial
handshake. This legitimate protocol message wasn't explicitly handled in
the handshake switch statement, causing it to fall through to the
default case.
The default case attempted to log a warning, which called
`logWithContext()`. This logging function accessed
`p.dest.conn.conn.LocalAddr()` which was nil during early handshake,
triggering a panic and container restart every 5-6 minutes.
## Changes Made
### 1. Defensive Logging (proxy.go)
Made `logWithContext()` nil-safe by checking all pointer levels before
accessing:
- Checks if `p.dest` is nil
- Checks if `p.dest.conn` is nil
- Checks if `p.dest.conn.conn` is nil
- Returns "not-connected" or "not-initialized" instead of panicking
### 2. Handle mining.extranonce.subscribe (handler_first_connect.go)
Added explicit case for `MiningExtranonceSubscribe` messages:
- Logs at debug level for visibility
- Forwards message transparently to pool
- Prevents falling through to unknown message handler
## Impact
- ✅ Resolves continuous crash loop since 2026-02-10 13:16 ET
- ✅ Enables modern miners with extranonce support to connect properly
- ✅ Future-proofs logging against similar edge cases with nil
connections
- ✅ No performance impact (just pointer checks)
## Testing
- Code compiles successfully
- Crash pattern analysis confirms this fixes the exact panic location
- Logs show the message is a legitimate Stratum extension that should
pass through
## CloudWatch Evidence
All crashes showed identical stack trace:
```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x110 pc=0x90b25f]
at proxy.go:453 in logWithContext()
```
Preceded by unknown message logs showing `mining.extranonce.subscribe`.
Made with [Cursor](https://cursor.com)2 files changed
Lines changed: 22 additions & 1 deletion
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
453 | | - | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
454 | 470 | | |
0 commit comments