Skip to content

Comments

fix: handle mining.extranonce.subscribe and prevent nil pointer crash - STG#84

Merged
abs2023 merged 4 commits intostgfrom
dev
Feb 10, 2026
Merged

fix: handle mining.extranonce.subscribe and prevent nil pointer crash - STG#84
abs2023 merged 4 commits intostgfrom
dev

Conversation

@abs2023
Copy link
Contributor

@abs2023 abs2023 commented Feb 10, 2026

No description provided.

abs2023 and others added 4 commits January 30, 2026 09:42
- Changed the subgraph client URLs in `client_test.go` to point to the new Graph API endpoint for the Lumerin Futures subgraph.
- Ensured that both `TestGetAllPositions` and `TestGetPositionsBySeller` use the updated URL for consistency in testing.
- Changed the subgraph client URLs in `client_test.go` to point to the
new Graph API endpoint for the Lumerin Futures subgraph.
- Ensured that both `TestGetAllPositions` and `TestGetPositionsBySeller`
use the updated URL for consistency in testing.
Fixes crash loop caused by new miners sending mining.extranonce.subscribe
messages during handshake phase.

Changes:
1. Made logWithContext() defensive against nil destination connections
   - Prevents panic when logging before connection fully established
   - Returns "not-connected" instead of crashing on nil pointer dereference

2. Added explicit handling for MiningExtranonceSubscribe messages
   - Properly forwards extranonce subscription requests to pool
   - Logs at debug level for visibility
   - Prevents falling through to unknown message handler

Root Cause:
New miners added to seller node send mining.extranonce.subscribe during
initial handshake. This legitimate Stratum extension message wasn't
explicitly handled, causing it to fall through to default case. The
logging in default case attempted to access p.dest.conn.conn.LocalAddr()
which was nil during early handshake, triggering panic and container
restart every 5-6 minutes.

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

Co-authored-by: Cursor <cursoragent@cursor.com>
…#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)
@abs2023 abs2023 merged commit 935cc53 into stg Feb 10, 2026
9 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