Skip to content

Race condition in new_session() in some environments (e.g. PyInstaller + Python 3.13+ + Docker) #624

@neubig

Description

@neubig

server.new_session() fails with TmuxObjectDoesNotExist due to a seeming race condition in some settings.
Specifically, I noticed it in PyInstaller-bundled binaries running Python 3.13+ inside Docker containers.

Root Cause

new_session() creates a session then immediately queries list-sessions to fetch session data. In certain environments, the session is not yet visible to list-sessions. Specifically, it seems that Python 3.13 and above encounters this issue, but Python 3.12 does not.

Affected Environments

Environment Result
Python 3.12 + PyInstaller + Docker ✅ Pass
Python 3.13 + PyInstaller + Docker 100% Fail
Python 3.13 + PyInstaller + Native ✅ Pass

Reproduction Script

#!/bin/bash
set -e
WORK_DIR=$(mktemp -d)
trap "sudo rm -rf $WORK_DIR 2>/dev/null || rm -rf $WORK_DIR" EXIT
cd "$WORK_DIR"

cat > test_libtmux.py << 'PYTEST'
import sys, uuid
import libtmux
from libtmux.exc import TmuxObjectDoesNotExist

server = libtmux.Server()
failures = 0
for i in range(10):
    try:
        session = server.new_session(session_name=f"test-{uuid.uuid4().hex[:8]}", x=80, y=24)
        session.kill()
    except TmuxObjectDoesNotExist:
        failures += 1
        print(f"  [{i+1}] FAILED")
print(f"Results: {10-failures}/10 passed")
sys.exit(1 if failures else 0)
PYTEST

docker run --rm -v "$WORK_DIR:/work" -w /work python:3.13-slim bash -c "
    apt-get update -qq && apt-get install -y -qq binutils tmux >/dev/null 2>&1
    pip install -q libtmux pyinstaller
    pyinstaller --onefile --clean --noconfirm --log-level ERROR test_libtmux.py 2>/dev/null
    ./dist/test_libtmux
"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions