{"record":{"id":"f44feaa9d48e6e2e","repo":"apache/pulsar","slug":"interrupted-while-creating-transaction","errorCode":null,"errorMessage":"Interrupted while creating transaction","messagePattern":"Interrupted while creating transaction","errorType":"exception","errorClass":"org.apache.pulsar.client.impl.v5.PulsarClientException","httpStatus":null,"severity":"warning","filePath":"pulsar-client-v5/src/main/java/org/apache/pulsar/client/impl/v5/PulsarClientV5.java","lineNumber":88,"sourceCode":"    public <T> QueueConsumerBuilder<T> newQueueConsumer(Schema<T> schema) {\n        return new QueueConsumerBuilderV5<>(this, schema);\n    }\n\n    @Override\n    public <T> CheckpointConsumerBuilder<T> newCheckpointConsumer(Schema<T> schema) {\n        return new CheckpointConsumerBuilderV5<>(this, schema);\n    }\n\n    @Override\n    public Transaction newTransaction() throws PulsarClientException {\n        try {\n            return newTransactionAsync().get();\n        } catch (ExecutionException e) {\n            Throwable cause = e.getCause() != null ? e.getCause() : e;\n            throw new PulsarClientException(cause.getMessage(), cause);\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new PulsarClientException(\"Interrupted while creating transaction\", e);\n        }\n    }\n\n    @Override\n    public CompletableFuture<Transaction> newTransactionAsync() {\n        var builder = v4Client.newTransaction();\n        if (transactionTimeout != null) {\n            builder.withTransactionTimeout(transactionTimeout.toMillis(), TimeUnit.MILLISECONDS);\n        }\n        return builder.build().thenApply(v4Txn -> (Transaction) new TransactionV5(v4Txn));\n    }\n\n    @Override\n    public void close() throws PulsarClientException {\n        try {\n            v4Client.close();\n        } catch (org.apache.pulsar.client.api.PulsarClientException e) {\n            throw new PulsarClientException(e.getMessage(), e);","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-v5/src/main/java/org/apache/pulsar/client/impl/v5/PulsarClientV5.java#L70-L106","documentation":"newTransaction() blocks on the async future; if the calling thread is interrupted while waiting, an InterruptedException is caught, the interrupt flag is restored via Thread.currentThread().interrupt(), and a PulsarClientException with the fixed message 'Interrupted while creating transaction' is thrown. The error means the caller (or a shutdown path) interrupted the thread, not that the broker rejected the transaction.","triggerScenarios":"A thread calling newTransaction() is interrupted while blocked in newTransactionAsync().get() — typically from an executor shutdownNow(), a timeout mechanism that interrupts workers, or application shutdown.","commonSituations":"Cancelling in-flight work via ExecutorService.shutdownNow(); framework code interrupting request-handling threads on request timeout; JVM shutdown hooks interrupting client threads.","solutions":["Check who interrupted the thread — usually a shutdown or timeout mechanism — and decide whether transaction creation should be allowed to finish","Preserve/respect the interrupt: the library already re-sets the interrupt flag; avoid swallowing it in your own code","Avoid calling blocking newTransaction() from threads subject to interruption; prefer newTransactionAsync() and handle completion asynchronously"],"exampleFix":"// before\nTransaction tx = client.newTransaction(); // blocking, interruptible\n// after\nTransaction tx = client.newTransactionAsync()\n    .orTimeout(30, TimeUnit.SECONDS)\n    .join();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Transaction tx = client.newTransaction();\n} catch (PulsarClientException e) {\n    if (Thread.currentThread().isInterrupted()) {\n        log.warn(\"Transaction creation interrupted; aborting\");\n    } else {\n        throw e;\n    }\n}","preventionTips":["Avoid shutdownNow()/interrupts on threads doing client calls; use async timeouts instead","Prefer newTransactionAsync().orTimeout(...) over blocking calls","Restore and check the interrupt flag in your own cleanup code"],"tags":["transactions","interrupted","concurrency"],"backgroundTag":"thread-interrupted","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}