jax-ml/jax · error · ValueError

Only one profiler server can be active at a time.

Error message

Only one profiler server can be active at a time.

What it means

jax.profiler.start_server is a process-global singleton; a second call while a server is already running raises ValueError. The module-level `_profiler_server` guard enforces one profiler server per process.

Source

Thrown at jax/_src/profiler.py:70

def start_server(
    port: int, requires_backend: bool = True
) -> _profiler.ProfilerServer:
  """Starts the profiler server on port `port`.

  Using the "TensorFlow profiler" feature in `TensorBoard
  <https://www.tensorflow.org/tensorboard>`_ 2.2 or newer, you can
  connect to the profiler server and sample execution traces that show CPU,
  GPU, and/or TPU device activity.

  Args:
    port: The port to start the profiler server on.
    requires_backend: If False, the profiler server will not wait for backends
      to be initialized before starting. Default is True.
  """
  global _profiler_server
  if _profiler_server is not None:
    raise ValueError("Only one profiler server can be active at a time.")

  # Make sure backends are initialized before creating a profiler
  # session. Otherwise on Cloud TPU, libtpu may not be initialized before
  # creating the tracer, which will cause the TPU tracer initialization to
  # fail and no TPU operations will be included in the profile.
  # NOTE(skyewm): I'm not sure this is necessary for start_server (is definitely
  # is for start_trace), but I'm putting it here to be safe.
  if requires_backend:
    xla_bridge.get_backend()

  _profiler_server = _profiler.start_server(port)
  return _profiler_server


def stop_server():
  """Stops the running profiler server."""
  global _profiler_server
  if _profiler_server is None:

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Call `jax.profiler.stop_server()` before starting again
  2. Guard with a module-level flag or try/except around start_server
  3. In tests, use setUp/tearDown pairing so each start is matched by a stop

Example fix

# before
jax.profiler.start_server(9999)  # second call fails
# after
try:
  jax.profiler.start_server(9999)
except ValueError:
  jax.profiler.stop_server()
  jax.profiler.start_server(9999)
Defensive patterns

Strategy: try-catch

Try / catch

try:
    jax.profiler.start_server(port)
except ValueError as e:
    if 'Only one profiler server' in str(e):
        jax.profiler.stop_server()
        jax.profiler.start_server(port)
    else:
        raise

Prevention

When it happens

Trigger: Calling `jax.profiler.start_server(port)` twice, e.g. in repeated notebook cell runs, test setup that runs per-test, or both library and user code starting a server.

Common situations: Test suites calling start_server in setUp without stop_server in tearDown; long-running servers where an init path may run twice; Kaggle/colab cell re-execution.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/fd4360d4c8246596. Report an issue: GitHub.