{"record":{"id":"e6242fd4c9385264","repo":"apache/beam","slug":"errors","errorCode":null,"errorMessage":"Errors: {}","messagePattern":"Errors: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"warning","filePath":"sdks/python/apache_beam/runners/portability/portable_runner.py","lineNumber":616,"sourceCode":"    if on_exit and self._cleanup_callbacks:\n      _LOGGER.info(\n          'Running cleanup on exit. If your pipeline should continue running, '\n          'be sure to use the following syntax:\\n'\n          '  with Pipeline() as p:\\n'\n          '    p.apply(..)\\n'\n          'This ensures that the pipeline finishes before this program exits.')\n    callback_exceptions = []\n    for callback in self._cleanup_callbacks:\n      try:\n        callback()\n      except Exception as e:\n        callback_exceptions.append(e)\n\n    self._cleanup_callbacks = ()\n    if callback_exceptions:\n      formatted_exceptions = ''.join(\n          [f\"\\n\\t{repr(e)}\" for e in callback_exceptions])\n      raise RuntimeError('Errors: {}'.format(formatted_exceptions))\n","sourceCodeStart":598,"sourceCodeEnd":617,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/portability/portable_runner.py#L598-L617","documentation":"After cancellation or a terminal state, _cleanup() runs registered cleanup callbacks; if any of them raised, it aggregates all exceptions and raises a single RuntimeError('Errors: {...}') with repr of each. It signals that job teardown (e.g. stopping message threads) partially failed.","triggerScenarios":"Calling cancel() or reaching a terminal state in _observe_state while one or more registered _cleanup_callbacks raised exceptions.","commonSituations":"Network drops when closing gRPC streams to the job service during cleanup; exceptions in user-registered cleanup hooks; cancel racing with job completion.","solutions":["Read the aggregated reprs in the message to identify which callbacks failed.","Ensure the job endpoint is reachable — cleanup usually fails from connection errors; reconnect and re-cancel if needed.","Wrap cancel() in try/except since the job may already be terminal.","Fix or remove faulty custom cleanup callbacks registered on the result handle."],"exampleFix":"try:\n    result.cancel()\nexcept RuntimeError as e:\n    print('cleanup issues (job may already be done):', e)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result.cancel()\nexcept RuntimeError as e:\n    # aggregated cleanup callback failures; job may already be terminal\n    print('cleanup errors:', e)","preventionTips":["Keep the job endpoint reachable until the result handle is fully cleaned up.","Avoid registering cleanup callbacks that can raise.","Expect cancel() to fail benignly if the job already finished."],"tags":["cleanup","callbacks","lifecycle"],"backgroundTag":"cleanup-callback-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"}