Skip to content

Duration settings can't be set through LIVEKIT_* env vars or generated flags #4938

Closed

Description

@mnjalale

Describe the bug
Every config setting has a generated command-line flag and a LIVEKIT_* environment variable (GenerateCLIFlags in pkg/config/config.go). For the 75 settings of type time.Duration, such as room.create_room_timeout and api.execution_timeout, the generated flag is a cli.Int64Flag:

case reflect.Int64:
	flag = &cli.Int64Flag{

As a result:

  • A duration string such as 30s makes the server exit at startup. That is the format the YAML config requires, and the format help-verbose shows as the default (--room.create_room_timeout int ... (default: 10s)).
    could not parse "30s" as int64 value from environment variable "LIVEKIT_ROOM_CREATE_ROOM_TIMEOUT" for flag room.create_room_timeout: strconv.ParseInt: parsing "30s": invalid syntax
    
  • A number without a unit is accepted and read as nanoseconds. LIVEKIT_ROOM_CREATE_ROOM_TIMEOUT=30 sets a 30ns timeout. The server starts normally, and then RoomService.CreateRoom fails within a few milliseconds with twirp error unavailable: no response from servers.

The only way to set these settings correctly from the environment is to give the value in nanoseconds, e.g. 30000000000. The YAML config itself rejects that form.

Server

  • Version: master (af2959d) and v1.13.7. Duration fields have used Int64Flag since generated flags were added in Generated CLI Flags #1112 (v1.3.0).
  • Environment: any. Reproduced single-node with --dev.

Client

  • Any. The bare-number case was observed with RoomService.CreateRoom over Twirp.

To Reproduce

  1. LIVEKIT_ROOM_CREATE_ROOM_TIMEOUT=30s livekit-server --dev. The server exits with the error above.
  2. livekit-server --dev --api.execution_timeout=5s. The server exits with invalid value "5s" for flag -api.execution_timeout: strconv.ParseInt: parsing "5s": invalid syntax.
  3. LIVEKIT_ROOM_CREATE_ROOM_TIMEOUT=30 livekit-server --dev, then call RoomService.CreateRoom. The server starts, and the call fails with unavailable. Without the variable, the same call succeeds.

Expected behavior
Duration settings set through a flag or LIVEKIT_* variable take the same values as in the YAML config: 30s is accepted, and 30 is rejected because it has no unit.

Workaround
Set duration settings in the YAML config (--config or LIVEKIT_CONFIG).

Possible fix
In GenerateCLIFlags, create a cli.DurationFlag for time.Duration fields. updateFromCLI already converts the flag's value to the field's type, so nothing else needs to change.

This rejects the bare-number form that flags and env vars currently accept as nanoseconds, as the YAML config already does. A deployment that sets nanosecond values today would need to switch to values like 30s.

I have opened a PR with this fix and a test; it is linked below.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions