{"record":{"id":"a8ff0e1ba341747d","repo":"apache/shardingsphere","slug":"invalid-transaction-handle-d","errorCode":null,"errorMessage":"Invalid transaction handle: %d","messagePattern":"Invalid transaction handle: (.+?)","errorType":"exception","errorClass":"InvalidTransactionHandleException","httpStatus":null,"severity":"error","filePath":"proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdCommitTransactionCommandExecutor.java","lineNumber":58,"sourceCode":"    \n    private final ConnectionSession connectionSession;\n    \n    @Override\n    public Collection<DatabasePacket> execute() throws SQLException {\n        int transactionHandle = packet.getTransactionId();\n        validateTransactionHandle(transactionHandle);\n        if (!connectionSession.isAutoCommit()) {\n            ProxyBackendTransactionManager transactionManager = new ProxyBackendTransactionManager(connectionSession.getDatabaseConnectionManager());\n            // TODO add rollback and return exception\n            transactionManager.commit();\n        }\n        FirebirdTransactionIdGenerator.getInstance().closeTransaction(connectionSession.getConnectionId(), transactionHandle);\n        return Collections.singleton(new FirebirdGenericResponsePacket());\n    }\n    \n    private void validateTransactionHandle(final int transactionHandle) {\n        if (!FirebirdTransactionIdGenerator.getInstance().isTransactionActive(connectionSession.getConnectionId(), transactionHandle)) {\n            throw new InvalidTransactionHandleException(transactionHandle);\n        }\n    }\n}\n","sourceCodeStart":40,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdCommitTransactionCommandExecutor.java#L40-L62","documentation":"InvalidTransactionHandleException thrown by FirebirdCommitTransactionCommandExecutor.validateTransactionHandle when the transaction handle in a COMMIT packet is not registered as active for the connection in FirebirdTransactionIdGenerator. The proxy tracks per-connection transaction handles; committing an unknown or already-closed handle is rejected.","triggerScenarios":"execute() calls isTransactionActive(connectionSession.getConnectionId(), transactionHandle) before committing; false when the handle was never opened by a START TRANSACTION, was already committed/rolled back, or belongs to a different connection.","commonSituations":"double COMMIT (client retries after timeout, first commit succeeded); handle reuse after rollback; two-phase or pooled clients carrying transaction handles across reconnects; client sending COMMIT for a transaction started on another attachment.","solutions":["Commit each transaction handle exactly once; after commit or rollback, discard the handle and start a new transaction.","On ambiguous timeout errors, do not blind-retry COMMIT; check transaction state (or reconnect) first, since the handle is closed by a successful commit.","Keep transaction start/commit on the same connection/attachment."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"Set<Long> activeTx = new HashSet<>();\nif (!activeTx.contains(trHandle)) throw new IllegalStateException(\"transaction not active\");\nsendCommit(trHandle);\nactiveTx.remove(trHandle);","typeGuard":null,"tryCatchPattern":"catch (SQLException e) {\n    if (e.getMessage().contains(\"Invalid transaction handle\")) {\n        // handle already committed/closed elsewhere: treat as success only if state confirms it\n        verifyTransactionClosed(); startNewTransaction();\n    } else throw e;\n}","preventionTips":["Commit each handle exactly once and remove it from client state afterwards.","Never blind-retry COMMIT after a timeout; verify state first.","Do not carry transaction handles across reconnects."],"tags":["firebird","transaction","commit","statement-handle"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}