mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-07 13:00:59 +08:00
reliability: wrap all 27 bare goroutines with safe.Go/GoNamed panic recovery
Applied safe.GoNamed to: - 9 exchange order_sync goroutines (OKX, Hyperliquid, Aster, Bybit, KuCoin, Gate, Bitget, Lighter, Binance×2) - Drawdown monitor (auto_trader_risk.go) - Brain news scanner + market briefs (agent/brain.go) - Sentinel scanner (agent/sentinel.go) - Agent scheduler (agent/scheduler.go) - x402 idle watchdog (mcp/payment/x402.go) - MCP stream idle watchdog (mcp/client.go) - Rate limiter cleanup (api/rate_limiter.go) - 3 telemetry fire-and-forget sends (telemetry/experience.go) - CoinAnk WS handler (provider/coinank/coinank_api/kline_ws.go) - API server goroutine (main.go) Added manual defer/recover with error reporting to: - Telegram AI agent handler (sends error msg to user on panic) - Trader data fetch (returns error result on panic to prevent deadlock) Before: a panic in ANY of these 27 goroutines would crash the entire trading process with zero diagnostics. Now all panics are caught, logged with stack traces, and the process continues running.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"nofx/safe"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -689,7 +690,7 @@ func (client *Client) CallWithRequestStream(req *Request, onChunk func(string))
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
resetCh := make(chan struct{}, 1)
|
||||
go func() {
|
||||
safe.GoNamed("mcp-stream-idle-watchdog", func() {
|
||||
t := time.NewTimer(idleTimeout)
|
||||
defer t.Stop()
|
||||
for {
|
||||
@@ -710,7 +711,7 @@ func (client *Client) CallWithRequestStream(req *Request, onChunk func(string))
|
||||
t.Reset(idleTimeout)
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
httpReq = httpReq.WithContext(ctx)
|
||||
resp, err := client.HTTPClient.Do(httpReq)
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"nofx/mcp"
|
||||
"nofx/safe"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -405,7 +406,7 @@ func X402CallStream(c *mcp.Client, signFn X402SignFunc, tag string, systemPrompt
|
||||
|
||||
// Start idle-timeout watchdog AFTER the 402 dance is done.
|
||||
resetCh := make(chan struct{}, 1)
|
||||
go func() {
|
||||
safe.GoNamed("x402-idle-watchdog", func() {
|
||||
t := time.NewTimer(x402StreamIdleTimeout)
|
||||
defer t.Stop()
|
||||
for {
|
||||
@@ -426,7 +427,7 @@ func X402CallStream(c *mcp.Client, signFn X402SignFunc, tag string, systemPrompt
|
||||
t.Reset(x402StreamIdleTimeout)
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
onLine := func() {
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user