Repository navigation
Description
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
30smakes the server exit at startup. That is the format the YAML config requires, and the formathelp-verboseshows 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=30sets a 30ns timeout. The server starts normally, and thenRoomService.CreateRoomfails within a few milliseconds withtwirp 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
Int64Flagsince 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.CreateRoomover Twirp.
To Reproduce
LIVEKIT_ROOM_CREATE_ROOM_TIMEOUT=30s livekit-server --dev. The server exits with the error above.livekit-server --dev --api.execution_timeout=5s. The server exits withinvalid value "5s" for flag -api.execution_timeout: strconv.ParseInt: parsing "5s": invalid syntax.LIVEKIT_ROOM_CREATE_ROOM_TIMEOUT=30 livekit-server --dev, then callRoomService.CreateRoom. The server starts, and the call fails withunavailable. 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