{"record":{"id":"2f77d3c554e815e3","repo":"t8y2/dbx","slug":"unknown-query-session-sessionid","errorCode":null,"errorMessage":"Unknown query session: \" + sessionId","messagePattern":"Unknown query session: \" \\+ sessionId","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java","lineNumber":1265,"sourceCode":"\n    private static void restorePagedQueryTransaction(Connection connection, boolean restoreAutoCommit) {\n        if (!restoreAutoCommit) {\n            return;\n        }\n        try {\n            connection.rollback();\n        } catch (SQLException ignored) {\n        }\n        try {\n            connection.setAutoCommit(true);\n        } catch (SQLException ignored) {\n        }\n    }\n\n    private static JsonNode fetchQueryPage(String sessionId, int pageSize) throws SQLException {\n        QuerySession session = QUERY_SESSIONS.get(sessionId);\n        if (session == null) {\n            throw new IllegalArgumentException(\"Unknown query session: \" + sessionId);\n        }\n        return readQuerySessionPage(session, pageSize);\n    }\n\n    private static JsonNode readQuerySessionPage(QuerySession session, int pageSize) throws SQLException {\n        int effectivePageSize = Math.max(1, pageSize);\n        ArrayNode rows = MAPPER.createArrayNode();\n        boolean truncated = false;\n\n        while (rows.size() < effectivePageSize && session.rowsReturned < session.maxRows) {\n            ArrayNode row;\n            if (session.pendingRow != null) {\n                row = session.pendingRow;\n                session.pendingRow = null;\n            } else {\n                if (!session.resultSet.next()) {\n                    closeQuerySession(session.id);\n                    return queryPageResult(session, rows, false, false);","sourceCodeStart":1247,"sourceCodeEnd":1283,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java#L1247-L1283","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Re-execute the original query to obtain a fresh sessionId, then paginate with the new id.","Paginate fully before the session expires/gets evicted — increase page size or speed up fetching.","Ensure all page requests go to the same plugin instance/process; pin requests to one worker or share session state.","Handle this error by restarting pagination from the first page instead of treating it as fatal data loss."],"exampleFix":"// before\npage2 = fetchQueryPage(\"sess-42\", 500);   // session evicted -> error\n// after\nresult = executeQuery(sql);                // fresh session\nfor (page : result.pages()) consume(page); // paginate before expiry","handlingStrategy":"retry","validationCode":"// Java: validate sessionId shape before paginating\nif (sessionId == null || sessionId.isBlank())\n    throw new IllegalArgumentException(\"sessionId required; run the query first\");","typeGuard":null,"tryCatchPattern":"try {\n    page = plugin.fetchQueryPage(sessionId, pageSize);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unknown query session\")) {\n        result = plugin.executeQuery(sql);      // session expired/evicted: restart\n        page = result.firstPage();\n    } else {\n        throw e;\n    }\n}","preventionTips":["Fetch all pages promptly after the query instead of holding session ids across long gaps","Never persist session ids across process restarts or redeployments","Route all pagination requests to the same plugin instance/worker","Use a larger pageSize if eviction is likely before you finish consuming pages"],"tags":["jdbc","pagination","session-state"],"backgroundTag":"unknown-session-id","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}