{"record":{"id":"ca2e4dba632b4093","repo":"jax-ml/jax","slug":"no-active-profiler-server","errorCode":null,"errorMessage":"No active profiler server.","messagePattern":"No active profiler server\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/profiler.py","lineNumber":89,"sourceCode":"\n  # Make sure backends are initialized before creating a profiler\n  # session. Otherwise on Cloud TPU, libtpu may not be initialized before\n  # creating the tracer, which will cause the TPU tracer initialization to\n  # fail and no TPU operations will be included in the profile.\n  # NOTE(skyewm): I'm not sure this is necessary for start_server (is definitely\n  # is for start_trace), but I'm putting it here to be safe.\n  if requires_backend:\n    xla_bridge.get_backend()\n\n  _profiler_server = _profiler.start_server(port)\n  return _profiler_server\n\n\ndef stop_server():\n  \"\"\"Stops the running profiler server.\"\"\"\n  global _profiler_server\n  if _profiler_server is None:\n    raise ValueError(\"No active profiler server.\")\n  _profiler_server = None # Should destroy the profiler server\n\n\ndef register_subprocess(pid: int, port: int) -> Callable[[], None]:\n  \"\"\"Registers a subprocess's profiler server to be profiled alongside the current process.\n\n  When the current process collects a profile (either programmatically or via\n  its profiler server), it will propagate the request to all registered\n  subprocesses' profiler servers and subsequently, aggregate all their responses\n  into the main response returned by this process's profiler server.\n\n  This is helpful when running workers in separate processes that may affect the\n  performance of the main process (e.g. PyGrain).\n\n  NOTE: Currently, only CPU profiling of subprocesses is supported.\n\n  Args:\n    pid: The process ID of the subprocess.","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/profiler.py#L71-L107","documentation":"jax.profiler.stop_server raises ValueError when no profiler server is currently running; the global `_profiler_server` is None. It is the counterpart guard to start_server's singleton check.","triggerScenarios":"Calling `jax.profiler.stop_server()` before any successful start_server, or after stop_server was already called.","commonSituations":"Cleanup code (finally blocks, tearDown) running when startup failed or was skipped; paired tests where ordering varies.","solutions":["Track server state in your own flag and only stop when started","Wrap stop_server in try/except ValueError for idempotent cleanup","Ensure tearDown only runs after a successful setUp start"],"exampleFix":"# before\njax.profiler.stop_server()  # may raise\n# after\ntry:\n  jax.profiler.stop_server()\nexcept ValueError:\n  pass","handlingStrategy":"try-catch","validationCode":"import jax.profiler as jp\n# track your own state\nserver_started = False","typeGuard":null,"tryCatchPattern":"try:\n    jp.stop_server()\nexcept ValueError:\n    pass  # nothing to stop; idempotent cleanup","preventionTips":["Only stop when your code started it","Use try/finally with a started flag"],"tags":["jax","profiler","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}