benbjohnson/litestream · error

timeout must be greater than 0

Error message

timeout must be greater than 0

What it means

The `litestream info` command validates that the --timeout flag is strictly greater than 0 seconds. A zero or negative timeout would create an http.Client with no usable timeout semantics (0 means no timeout) or an immediately-expiring one, so Run rejects it up front. The value is later converted to time.Duration via time.Duration(*timeout) * time.Second.

Source

Thrown at cmd/litestream/info.go:35

type InfoCommand struct{}

// Run executes the info command.
func (c *InfoCommand) Run(_ context.Context, args []string) error {
	fs := flag.NewFlagSet("litestream-info", flag.ContinueOnError)
	socketPath := fs.String("socket", "/var/run/litestream.sock", "control socket path")
	timeout := fs.Int("timeout", 10, "timeout in seconds")
	jsonOutput := fs.Bool("json", false, "output raw JSON")
	fs.Usage = c.Usage
	if err := fs.Parse(args); err != nil {
		return err
	}

	if fs.NArg() > 0 {
		return fmt.Errorf("too many arguments")
	}

	if *timeout <= 0 {
		return fmt.Errorf("timeout must be greater than 0")
	}

	clientTimeout := time.Duration(*timeout) * time.Second
	client := &http.Client{
		Timeout: clientTimeout,
		Transport: &http.Transport{
			DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
				return net.DialTimeout("unix", *socketPath, clientTimeout)
			},
		},
	}

	resp, err := client.Get("http://localhost/info")
	if err != nil {
		return fmt.Errorf("failed to connect to control socket: %w", err)
	}
	defer resp.Body.Close()

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Pass a positive integer of seconds, e.g. `litestream info --timeout 30`.
  2. In scripts, default the variable when unset: TIMEOUT=${TIMEOUT:-30} before invoking the command.
  3. Omit the flag entirely to use the built-in default if you only need a reasonable HTTP timeout.

Example fix

// before
$ litestream info --timeout 0
// after
$ litestream info --timeout 30
Defensive patterns

Strategy: validation

Validate before calling

if (!(Number.isInteger(timeout) && timeout > 0)) {
  throw new Error('info --timeout must be a positive integer of seconds');
}

Prevention

When it happens

Trigger: Running `litestream info --timeout 0`, `--timeout -5`, or a shell variable expanding to 0/empty-numeric in a script that builds the command line.

Common situations: Templated scripts or CI jobs where TIMEOUT env var is unset and defaults to 0; users who think 0 means 'no timeout' and pass 0 explicitly; signed/unsigned confusion when computing the value.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/51b2b8806abb2612. Report an issue: GitHub.