t8y2/dbx · error · IllegalArgumentException

Unknown query session: " + sessionId

Error message

Unknown query session: " + sessionId

What it means

fetchQueryPage looks up a paged query result by sessionId in the QUERY_SESSIONS map. If the id is absent, the plugin throws this IllegalArgumentException: pagination was requested for a session that was never started or has been evicted/expired.

Source

Thrown at plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java:1265

    private static void restorePagedQueryTransaction(Connection connection, boolean restoreAutoCommit) {
        if (!restoreAutoCommit) {
            return;
        }
        try {
            connection.rollback();
        } catch (SQLException ignored) {
        }
        try {
            connection.setAutoCommit(true);
        } catch (SQLException ignored) {
        }
    }

    private static JsonNode fetchQueryPage(String sessionId, int pageSize) throws SQLException {
        QuerySession session = QUERY_SESSIONS.get(sessionId);
        if (session == null) {
            throw new IllegalArgumentException("Unknown query session: " + sessionId);
        }
        return readQuerySessionPage(session, pageSize);
    }

    private static JsonNode readQuerySessionPage(QuerySession session, int pageSize) throws SQLException {
        int effectivePageSize = Math.max(1, pageSize);
        ArrayNode rows = MAPPER.createArrayNode();
        boolean truncated = false;

        while (rows.size() < effectivePageSize && session.rowsReturned < session.maxRows) {
            ArrayNode row;
            if (session.pendingRow != null) {
                row = session.pendingRow;
                session.pendingRow = null;
            } else {
                if (!session.resultSet.next()) {
                    closeQuerySession(session.id);
                    return queryPageResult(session, rows, false, false);

View on GitHub (pinned to c0390bff16)

Solutions

  1. Re-execute the original query to obtain a fresh sessionId, then paginate with the new id.
  2. Paginate fully before the session expires/gets evicted — increase page size or speed up fetching.
  3. Ensure all page requests go to the same plugin instance/process; pin requests to one worker or share session state.
  4. Handle this error by restarting pagination from the first page instead of treating it as fatal data loss.

Example fix

// before
page2 = fetchQueryPage("sess-42", 500);   // session evicted -> error
// after
result = executeQuery(sql);                // fresh session
for (page : result.pages()) consume(page); // paginate before expiry
Defensive patterns

Strategy: retry

Validate before calling

// Java: validate sessionId shape before paginating
if (sessionId == null || sessionId.isBlank())
    throw new IllegalArgumentException("sessionId required; run the query first");

Try / catch

try {
    page = plugin.fetchQueryPage(sessionId, pageSize);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Unknown query session")) {
        result = plugin.executeQuery(sql);      // session expired/evicted: restart
        page = result.firstPage();
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling the fetch-page operation with a sessionId returned by a previous run after a plugin restart (static map cleared), after session eviction (map size limit/TTL), a typo'd/stale id, or a session created on a different plugin instance (multi-process setup).

Common situations: Long-running jobs paginating slowly while the session cache evicts old entries, load-balanced workers where page 2 hits a different process, or client restarts resuming pagination from a persisted session id.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/2f77d3c554e815e3. Report an issue: GitHub.