From 6e9d84647158e1846307c282815be249606a00e4 Mon Sep 17 00:00:00 2001 From: Siyuan Date: Thu, 13 Nov 2025 14:29:55 +0000 Subject: [PATCH] feat: panic on max restart attempts --- internal/native/native.go | 1 + internal/native/proxy.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/native/native.go b/internal/native/native.go index 131283a4..770da675 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -33,6 +33,7 @@ type NativeOptions struct { AppVersion *semver.Version DisplayRotation uint16 DefaultQualityFactor float64 + MaxRestartAttempts uint OnVideoStateChange func(state VideoState) OnVideoFrameReceived func(frame []byte, duration time.Duration) OnIndevEvent func(event string) diff --git a/internal/native/proxy.go b/internal/native/proxy.go index d4433b26..3057a83f 100644 --- a/internal/native/proxy.go +++ b/internal/native/proxy.go @@ -19,7 +19,8 @@ import ( ) const ( - maxFrameSize = 1920 * 1080 / 2 + maxFrameSize = 1920 * 1080 / 2 + defaultMaxRestartAttempts uint = 5 ) type nativeProxyOptions struct { @@ -55,6 +56,10 @@ func randomId(binaryLength int) string { func (n *NativeOptions) toProxyOptions() *nativeProxyOptions { // random 16 bytes hex string handshakeMessage := randomId(16) + maxRestartAttempts := defaultMaxRestartAttempts + if n.MaxRestartAttempts > 0 { + maxRestartAttempts = n.MaxRestartAttempts + } return &nativeProxyOptions{ Disable: n.Disable, SystemVersion: n.SystemVersion, @@ -67,6 +72,7 @@ func (n *NativeOptions) toProxyOptions() *nativeProxyOptions { OnVideoStateChange: n.OnVideoStateChange, OnNativeRestart: n.OnNativeRestart, HandshakeMessage: handshakeMessage, + MaxRestartAttempts: maxRestartAttempts, } } @@ -405,6 +411,10 @@ func (p *NativeProxy) restartProcess() error { } p.restarts++ + if p.restarts >= p.options.MaxRestartAttempts { + p.logger.Fatal().Msg("max restart attempts reached, exiting") + return fmt.Errorf("max restart attempts reached") + } if err := p.start(); err != nil { return fmt.Errorf("failed to start native process: %w", err)