sgl-project/sglang · error · ValueError

recycle_interval must be positive

Error message

recycle_interval must be positive

What it means

SharedMemoryPool (multimodal transport memory pool) validates its constructor arguments; recycle_interval controls how often the background recycler thread wakes to reclaim completed leases. A non-positive interval would make the recycler spin or fail to wait, so it is rejected upfront with ValueError.

Source

Thrown at python/sglang/srt/multimodal/transport/memory_pool.py:178

        self,
        *,
        memory_size: int,
        byte_tensor: torch.Tensor,
        base_address: int,
        device_id: int,
        consumer_count: int,
        recycle_interval: float,
        transport_name: str,
        max_inflight_slices: int = DEFAULT_MAX_INFLIGHT_SLICES,
    ) -> None:
        if memory_size <= 0:
            raise ValueError("memory_size must be positive")
        if consumer_count <= 0:
            raise ValueError("consumer_count must be positive")
        if max_inflight_slices <= 0:
            raise ValueError("max_inflight_slices must be positive")
        if recycle_interval <= 0:
            raise ValueError("recycle_interval must be positive")
        if (
            not byte_tensor.is_cuda
            or byte_tensor.device.index != device_id
            or byte_tensor.dtype != torch.uint8
            or not byte_tensor.is_contiguous()
            or byte_tensor.numel() < memory_size
        ):
            raise ValueError(
                "byte_tensor must be a sufficiently large contiguous uint8 tensor "
                f"on cuda:{device_id}"
            )

        self.memory_size = memory_size
        self.byte_tensor = byte_tensor
        self.base_address = base_address
        self.device_id = device_id
        self.consumer_count = consumer_count
        self.control_words_per_slot = 1 + consumer_count

View on GitHub (pinned to 0132848349)

Solutions

  1. Set recycle_interval to a positive number of seconds (e.g. 0.1–1.0)
  2. Check the config path feeding this constructor for a missing/zeroed recycle_interval field
  3. If a shorter/longer cadence is desired, tune the positive value rather than zeroing it

Example fix

// before
pool = SharedMemoryPool(..., recycle_interval=0)
// after
pool = SharedMemoryPool(..., recycle_interval=0.5)
Defensive patterns

Strategy: validation

Validate before calling

assert isinstance(recycle_interval, (int, float)) and recycle_interval > 0, 'recycle_interval must be > 0'

Prevention

When it happens

Trigger: Constructing SharedMemoryPool (directly or via a transport factory) with recycle_interval=0 or negative, e.g. passing a config value that was never set and defaulted to 0.

Common situations: YAML/JSON config missing the recycle interval key so it defaults to 0; unit tests constructing pools with placeholder integers; copy-paste of another pool's kwargs.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/dd47f33b864be2fd. Report an issue: GitHub.