diff --git a/packages/shared/gpu_encoder.py b/packages/shared/gpu_encoder.py index c217b92cf..37d3cf0c3 100644 --- a/packages/shared/gpu_encoder.py +++ b/packages/shared/gpu_encoder.py @@ -323,6 +323,7 @@ class GpuEncoderClient: raise GpuEncodeError("GPU_ENCODE_RELAY_SECRET not set") return secret + def _warm_up_if_needed(self) -> None: """POST 前预热:如果距上次成功通信超过 idle 阈值,先打 /health 打通 Tailscale 链路。 @@ -372,11 +373,13 @@ class GpuEncoderClient: first_byte_ok = True logger.debug( "[gpu-encoder] P4000 first byte in %.2fs (connect_timeout=%.1fs)", - time.time() - t0, - connect_timeout, + time.time() - t0, connect_timeout, ) - # 剩余用长超时 - resp.fp._sock.settimeout(ffmpeg_timeout + 60) + # 剩余用长超时(给底层socket放宽时限;如果是mock/不支持,则跳过) + try: + resp.fp._sock.settimeout(ffmpeg_timeout + 60) + except (AttributeError, OSError): + pass rest = resp.read() raw = (first_chunk + rest).decode("utf-8") resp.close() @@ -387,8 +390,10 @@ class GpuEncoderClient: except (urllib.error.URLError, socket.timeout, TimeoutError, ConnectionError, OSError) as e: waited = time.time() - t0 hint = "first-byte" if not first_byte_ok else "ffmpeg/upload" + # 统一以 "connection error" 开头,便于上层 fallback 逻辑用关键词识别; + # 末尾再附带具体错误(timed out / refused ...)供排障 raise GpuEncodeError( - f"P4000 {hint} timeout after {waited:.1f}s " + f"P4000 {hint} connection error after {waited:.1f}s " f"(connect_timeout={connect_timeout:.0f}s, ffmpeg_timeout={ffmpeg_timeout}s): {e}" ) from e finally: