{"record":{"id":"bd13a280aa482788","repo":"apache/beam","slug":"was-unable-to-reset-bundle-processor-safely-bundle-processor","errorCode":null,"errorMessage":"Was unable to reset bundle processor safely. Bundle processor will be discarded and re-instantiated on next bundle for descriptor {}.","messagePattern":"Was unable to reset bundle processor safely\\. Bundle processor will be discarded and re-instantiated on next bundle for descriptor (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdks/java/harness/src/main/java/org/apache/beam/fn/harness/control/ProcessBundleHandler.java","lineNumber":1025,"sourceCode":"    /**\n     * Finds an active bundle processor for the specified {@code instructionId} or null if one could\n     * not be found.\n     */\n    public BundleProcessor find(String instructionId) {\n      return activeBundleProcessors.get(instructionId);\n    }\n\n    /**\n     * Add a {@link BundleProcessor} to cache. The {@link BundleProcessor} will be marked as\n     * inactive and reset before being added to the cache.\n     */\n    void release(String bundleDescriptorId, BundleProcessor bundleProcessor) {\n      activeBundleProcessors.remove(bundleProcessor.getInstructionId());\n      try {\n        bundleProcessor.reset();\n        cachedBundleProcessors.get(bundleDescriptorId).add(bundleProcessor);\n      } catch (Exception e) {\n        LOG.warn(\n            \"Was unable to reset bundle processor safely. Bundle processor will be discarded and re-instantiated on next bundle for descriptor {}.\",\n            bundleDescriptorId,\n            e);\n      }\n    }\n\n    /** Discard an active {@link BundleProcessor} instead of being re-used. */\n    void discard(BundleProcessor bundleProcessor) {\n      bundleProcessor.discard();\n      activeBundleProcessors.remove(bundleProcessor.getInstructionId());\n    }\n\n    /** Shutdown all the cached {@link BundleProcessor}s, running the tearDown() functions. */\n    void shutdown() throws Exception {\n      cachedBundleProcessors.invalidateAll();\n    }\n  }\n","sourceCodeStart":1007,"sourceCodeEnd":1043,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/control/ProcessBundleHandler.java#L1007-L1043","documentation":"ProcessBundleHandler.release() calls BundleProcessor.reset() when returning a processor to the cache after a bundle; if reset() throws, this warning is logged and the processor is discarded instead of cached. The next bundle for that descriptor will pay the cost of re-instantiating the processor. Any exception thrown by DoFn StartBundle/FinishBundle cleanup paths or registered reset handlers surfaces here.","triggerScenarios":"bundleProcessor.reset() throws during release() after a bundle completes, typically because a DoFn's FinishBundle/setup-related state cleanup or a registered reset function raised an exception.","commonSituations":"DoFns holding external resources (connections, files) that fail to close cleanly; exceptions in FinishBundle; state corruption after a failed bundle.","solutions":["Fix the underlying exception included in the warning's stack trace (usually a failing close/finish callback).","Ensure DoFn external resources are closed idempotently and safely in FinishBundle/teardown.","Check for null or corrupted state after failed bundles before reset.","Investigate whether reset failures repeat for every bundle (then performance degrades — re-instantiation each time)."],"exampleFix":"// before\n@FinishBundle\npublic void finish(FinishContext ctx) {\n  writer.flush(); // throws if writer already closed\n}\n// after\n@FinishBundle\npublic void finish(FinishContext ctx) {\n  if (writer != null) {\n    try { writer.flush(); } catch (IOException ignored) {}\n  }\n}","handlingStrategy":"try-catch","validationCode":"// Validate closable resources are open before reset in FinishBundle\nif (writer == null || !writer.isOpen()) { LOG.warn(\"writer already closed; skip flush\"); }","typeGuard":null,"tryCatchPattern":"try {\n  bundleProcessor.reset();\n} catch (Exception e) {\n  LOG.warn(\"reset failed; processor will be recreated\", e);\n}","preventionTips":["Make reset/close paths idempotent","Close external resources in FinishBundle, not only teardown","Read the wrapped exception stack trace to fix the root cause","Watch for repeated occurrences — they degrade performance via re-instantiation"],"tags":["java","apache-beam","bundle-processor","resource-cleanup"],"backgroundTag":"resource-cleanup-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}