t8y2/dbx · error · IllegalArgumentException

Query session not found: {sessionId}

Error message

Query session not found: {sessionId}

What it means

JdbcExecutor throws IllegalArgumentException when a query-session lookup by sessionId finds no entry in the target session map. Sessions are created lazily by read methods and removed on close/expiration, so this indicates the caller referenced a session that the executor no longer tracks. The custom missingMessage lets each caller produce a specific 'Query session not found: {sessionId}' style message.

Source

Thrown at agents/common/src/main/java/com/dbx/agent/JdbcExecutor.java:706

            result.append(Character.forDigit((b >> 4) & 0xF, 16));
            result.append(Character.forDigit(b & 0xF, 16));
        }
        return result.toString();
    }

    private static String sqlXmlToString(SQLXML value) throws SQLException {
        return value == null ? null : value.getString();
    }

    private QueryPageResult fetchSessionPage(
        ConcurrentHashMap<String, QuerySession> targetSessions,
        String sessionId,
        int pageSize,
        String missingMessage
    ) {
        QuerySession session = targetSessions.get(sessionId);
        if (session == null) {
            throw new IllegalArgumentException(missingMessage);
        }
        synchronized (session) {
            try {
                return readSessionPage(targetSessions, session, pageSize, 0L);
            } catch (RuntimeException | Error error) {
                closeSession(targetSessions, sessionId);
                throw error;
            }
        }
    }

    private QueryPageResult readSessionPage(
        ConcurrentHashMap<String, QuerySession> targetSessions,
        QuerySession session,
        int pageSize,
        long executionTimeMs
    ) {
        return unchecked(() -> {

View on GitHub (pinned to c0390bff16)

Solutions

  1. Re-issue the original query to obtain a fresh sessionId, then page through results without gaps
  2. Check that the sessionId was not closed and that page fetches happen before session expiry/cleanup
  3. Ensure the same JdbcExecutor instance (or same agent session) is used for creating and reading the session
  4. On receiving this error, treat the session as gone and restart pagination from row 0

Example fix

// before
Page page = executor.readPage(sessionId, 100);
// after
Page page;
try {
    page = executor.readPage(sessionId, 100);
} catch (IllegalArgumentException e) {
    sessionId = executor.executeQuery(sql); // recreate session
    page = executor.readPage(sessionId, 100);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// caller-side: only use IDs obtained from a live query and not yet consumed/closed
if (sessionId == null || !activeSessions.contains(sessionId)) {
    sessionId = executor.executeQuery(sql); // recreate before paging
}

Type guard

boolean sessionAlive(String id) { return id != null && activeSessions.contains(id); }

Try / catch

try {
    page = executor.readPage(sessionId, pageSize);
} catch (IllegalArgumentException e) {
    sessionId = executor.executeQuery(sql); // session lost: restart pagination
    page = executor.readPage(sessionId, pageSize);
}

Prevention

When it happens

Trigger: Calling a paginated read API (e.g. query results paging) with a sessionId that was never created, was already closed (explicit close, cleanup, or session expiry), or that belongs to a different executor instance. Also occurs after closeSession ran as part of error recovery for a previous page read.

Common situations: Client restarts or reconnects and reuses a stale sessionId; sessions evicted by maintenance/cleanup between page fetches; copying a sessionId across agent sessions in multi-session mode; page reads after calling the close-session method.

Related errors


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