cayleygraph/cayley · error

couldn't parse connmaxlifetime string: %v

Error message

couldn't parse connmaxlifetime string: %v

What it means

After reading "connmaxlifetime", connect parses it with time.ParseDuration. If the string isn't a valid Go duration (e.g. "3600", "1 hr"), the parse error is wrapped as "couldn't parse connmaxlifetime string". Reached via Init or New.

Source

Thrown at graph/sql/quadstore.go:142

	maxIdleConnections, err := opts.IntKey("maxidleconnections", -1)

	if err != nil {
		return nil, fmt.Errorf("could not retrieve maxIdleConnections from options: %v", err)
	}

	connMaxLifetime, err := opts.StringKey("connmaxlifetime", "")

	if err != nil {
		return nil, fmt.Errorf("could not retrieve connmaxlifetime from options: %v", err)
	}

	var connDuration time.Duration
	if connMaxLifetime != "" {
		connDuration, err = time.ParseDuration(connMaxLifetime)

		if err != nil {
			return nil, fmt.Errorf("couldn't parse connmaxlifetime string: %v", err)
		}
	}

	// TODO(barakmich): Parse options for more friendly addr
	conn, err := sql.Open(flavor, addr)
	if err != nil {
		clog.Errorf("Couldn't open database at %s: %#v", addr, err)
		return nil, err
	}

	// "Open may just validate its arguments without creating a connection to the database."
	// "To verify that the data source name is valid, call Ping."
	// Source: http://golang.org/pkg/database/sql/#Open
	if err := conn.Ping(); err != nil {
		clog.Errorf("Couldn't open database at %s: %#v", addr, err)
		return nil, err
	}

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Use a valid Go duration string with units, e.g. "30m", "1h", "24h30m".
  2. Remember a bare number is invalid — it needs a unit suffix ("3600s" not "3600").
  3. Trim whitespace from the config value before passing it.

Example fix

// before
{"connmaxlifetime": "3600"}
// after
{"connmaxlifetime": "3600s"}
Defensive patterns

Strategy: validation

Validate before calling

if s, ok := opts["connmaxlifetime"].(string); ok && s != "" {
    if _, err := time.ParseDuration(s); err != nil {
        return fmt.Errorf("connmaxlifetime is not a valid Go duration: %v", err)
    }
}

Try / catch

qs, err := quadstore.New(addr, opts)
if err != nil {
    if strings.Contains(err.Error(), "couldn't parse connmaxlifetime") {
        // rewrite the value with an explicit unit, e.g. "1h"
    }
}

Prevention

When it happens

Trigger: New/Init where "connmaxlifetime" is a non-empty string that time.ParseDuration cannot parse — missing unit ("3600"), bad unit ("1 hour"), or malformed ("1h30m20").

Common situations: Admins writing seconds-as-number strings; config translated from other tools' formats ("1 hour", "3600s" is fine but "1h " with trailing space is not).

Understand the failure class

Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.

Related errors


AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06). Data as JSON: /api/errors/32abfe11f26b3da8. Report an issue: GitHub.