Release v1.4.7 with unlimited default timeout
This commit is contained in:
@@ -167,9 +167,6 @@ func New(cfg Config) *Service {
|
||||
if strings.TrimSpace(cfg.ShellType) == "" {
|
||||
cfg.ShellType = lingmaipc.DefaultShellType()
|
||||
}
|
||||
if cfg.Timeout <= 0 {
|
||||
cfg.Timeout = 300 * time.Second
|
||||
}
|
||||
if cfg.Transport == "" {
|
||||
cfg.Transport = lingmaipc.TransportAuto
|
||||
}
|
||||
@@ -225,6 +222,13 @@ func (s *Service) Close() error {
|
||||
return s.closeClientLocked()
|
||||
}
|
||||
|
||||
func contextWithOptionalTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc) {
|
||||
if timeout <= 0 {
|
||||
return context.WithCancel(parent)
|
||||
}
|
||||
return context.WithTimeout(parent, timeout)
|
||||
}
|
||||
|
||||
func (s *Service) State() State {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
@@ -365,7 +369,7 @@ func (s *Service) generateRemote(
|
||||
client := s.remoteClientLocked()
|
||||
var lastErr error
|
||||
for i, model := range models {
|
||||
attemptCtx, cancel := context.WithTimeout(ctx, s.cfg.Timeout)
|
||||
attemptCtx, cancel := contextWithOptionalTimeout(ctx, s.cfg.Timeout)
|
||||
result, emitted, err := s.generateRemoteWithModel(attemptCtx, client, req, prompt, model, onDelta)
|
||||
cancel()
|
||||
if err == nil {
|
||||
@@ -513,7 +517,7 @@ func (s *Service) generateLocked(
|
||||
req ChatRequest,
|
||||
onDelta func(string),
|
||||
) (result *ChatResult, err error) {
|
||||
requestCtx, cancel := context.WithTimeout(ctx, s.cfg.Timeout)
|
||||
requestCtx, cancel := contextWithOptionalTimeout(ctx, s.cfg.Timeout)
|
||||
defer cancel()
|
||||
|
||||
ipcClient, err := s.ensureConnected(requestCtx)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestIsRecoverableIPCError(t *testing.T) {
|
||||
@@ -23,3 +25,26 @@ func TestIsRecoverableIPCErrorIgnoresModelErrors(t *testing.T) {
|
||||
t.Fatal("timeout should not be treated as an immediate reconnect retry")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewKeepsZeroTimeoutUnlimited(t *testing.T) {
|
||||
svc := New(Config{Timeout: 0})
|
||||
if svc.cfg.Timeout != 0 {
|
||||
t.Fatalf("timeout = %v, want 0", svc.cfg.Timeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextWithOptionalTimeoutZeroDoesNotSetDeadline(t *testing.T) {
|
||||
ctx, cancel := contextWithOptionalTimeout(context.Background(), 0)
|
||||
defer cancel()
|
||||
if _, ok := ctx.Deadline(); ok {
|
||||
t.Fatal("zero timeout should not set a deadline")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextWithOptionalTimeoutPositiveSetsDeadline(t *testing.T) {
|
||||
ctx, cancel := contextWithOptionalTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if _, ok := ctx.Deadline(); !ok {
|
||||
t.Fatal("positive timeout should set a deadline")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user