{"record":{"id":"a6d9f4a1cc07beee","repo":"apache/beam","slug":"shared-server-process-died-unexpectedly-with-exit-code-exit","errorCode":null,"errorMessage":"Shared Server Process died unexpectedly with exit code {exit_code}","messagePattern":"Shared Server Process died unexpectedly with exit code (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/utils/multi_process_shared.py","lineNumber":508,"sourceCode":"      last_log = start_time\n      while True:\n        if os.path.exists(address_file):\n          break\n\n        if os.path.exists(error_file):\n          with open(error_file, 'r') as f:\n            error_msg = f.read()\n          try:\n            os.remove(error_file)\n          except OSError:\n            pass\n\n          if p.is_alive(): p.terminate()\n          raise RuntimeError(f\"Shared Server Process crashed:\\n{error_msg}\")\n\n        if not p.is_alive():\n          exit_code = p.exitcode\n          raise RuntimeError(\n              \"Shared Server Process died unexpectedly\"\n              f\" with exit code {exit_code}\")\n\n        if time.time() - last_log > 300:\n          logging.warning(\n              \"Still waiting for %s to initialize... %ss elapsed)\",\n              self._tag,\n              int(time.time() - start_time))\n          last_log = time.time()\n\n        time.sleep(0.05)\n\n      logging.info('External process successfully started for %s', self._tag)\n    else:\n      # We need to be able to authenticate with both the manager\n      # and the process.\n      self._serving_manager = _SingletonRegistrar(\n          address=('localhost', 0), authkey=AUTH_KEY)","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/utils/multi_process_shared.py#L490-L526","documentation":"Raised in _create_server when the spawned server process exits with a nonzero exit code before it finished initializing. Unlike errorIndex 4021 (the server wrote a traceback), here the process died without producing an error file, so Beam reports the raw exit code.","triggerScenarios":"The shared-object server process is terminated or crashes hard (segfault, OOM-kill, sys.exit, external terminate) during the startup wait loop in _get_manager.","commonSituations":"OOM killer killing the child; native code (numpy/tensorflow extensions) segfaulting at import; the process being killed by a resource manager or watchdog; exit() called in module-level code of the shared object's module.","solutions":["Check system logs (dmesg/journalctl) for OOM kills and increase memory limits","Identify and fix native-library crashes by importing/exercising the shared object in a standalone subprocess","Check the reported exit code: 137/-9 means SIGKILL (usually OOM), -11 means SIGSEGV (native crash)","Pin/upgrade libraries whose import crashes and ensure the environment matches your tested configuration"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# smoke-test the shared object creation in isolation\nproc = subprocess.Popen([sys.executable, '-c', 'obj = create_shared_object()'])\nrc = proc.wait(60)\nassert rc == 0, f'init subprocess died with {rc}'","typeGuard":null,"tryCatchPattern":"try:\n    handle = mps.acquire()\nexcept RuntimeError as e:\n    if 'died unexpectedly with exit code' in str(e):\n        code = int(e.args[0].rsplit(' ', 1)[-1]) if e.args else -1\n        if code in (-9, 137):\n            raise MemoryError('Shared server OOM-killed; increase memory') from e\n        raise","preventionTips":["Provision enough memory: exit code -9/137 usually means OOM kill","Test native-library imports in a clean subprocess before deploying","Avoid sys.exit()/crashes in module-level code of the shared object's module","Check dmesg/journalctl for SIGSEGV/SIGKILL of the child when diagnosing"],"tags":["python","multiprocessing","process-crash","exit-code"],"backgroundTag":"process-crashed","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"}