prestodb/presto · error · SQLException

Timeout is negative

Error message

Timeout is negative

What it means

isValid(int) throws SQLException("Timeout is negative") when the timeout argument is below zero. This matches the JDBC specification, where 0 means no timeout and negative values are invalid. The check runs before any connection-state inspection, so no network I/O occurs.

Source

Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoConnection.java:534

    public NClob createNClob()
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("createNClob");
    }

    @Override
    public SQLXML createSQLXML()
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("createSQLXML");
    }

    @Override
    public boolean isValid(int timeout)
            throws SQLException
    {
        if (timeout < 0) {
            throw new SQLException("Timeout is negative");
        }
        return !isClosed();
    }

    @Override
    public void setClientInfo(String name, String value)
            throws SQLClientInfoException
    {
        requireNonNull(name, "name is null");
        if (value != null) {
            clientInfo.put(name, value);
        }
        else {
            clientInfo.remove(name);
        }
    }

    @Override

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Pass a timeout >= 0; use 0 to skip the timeout
  2. Clamp with Math.max(0, timeout) before calling
  3. Treat an already-expired deadline as a failed validation instead of calling isValid with the negative remainder

Example fix

// before
boolean ok = connection.isValid(timeout);
// after
boolean ok = connection.isValid(Math.max(0, timeout));
Defensive patterns

Strategy: validation

Validate before calling

if (timeout < 0) {
    throw new IllegalArgumentException("timeout must be >= 0, got " + timeout);
}
boolean ok = connection.isValid(timeout);

Type guard

static boolean nonNegativeTimeout(int timeout) {
    return timeout >= 0;
}

Prevention

When it happens

Trigger: Calling connection.isValid(-1); passing user/config-supplied values without validation; computing a remaining timeout from a deadline that has already expired (deadline - now < 0).

Common situations: Connection pools configured with negative validation timeouts; watchdog code that subtracts timestamps and forwards the result directly to isValid.

Understand the failure class

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/2d92278479e8e240. Report an issue: GitHub.