[Bug] RPC server _serving() skips os.chdir(old_cwd) and sock.close() when worker exits non-zero, leaving server in deleted CWD

Aperta
#21,083 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@Anurag1428 ci sta già lavorando.

Dal 29/11/2026.

  • #21085 di @Anurag1428 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Read python/tvm/rpc/server.py around _serving() lines 138–178, then inspect the RPC server tests that exercise worker failures and timeouts. Reproduce a worker exit with a nonzero code and check whether the process restores its working directory and closes the socket; done means cleanup also runs on failure and the next session can be served.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

needs-triage type: bug
Summary

In python/tvm/rpc/server.py:138-178, _serving() creates a temporary directory work_path, changes into it via old_cwd = os.getcwd(); os.chdir(work_path.path), and does not wrap the body in try ... finally:

old_cwd = os.getcwd()
os.chdir(work_path.path)
...
elif server_proc.exitcode != 0:
    raise RuntimeError(...)

logger.info(f"finish serving {addr}")
os.chdir(old_cwd)
work_path.remove()
sock.close()

When the child worker process exits non-zero (e.g., segfault/abort), raise RuntimeError(...) skips os.chdir(old_cwd), work_path.remove(), and sock.close(). When work_path (TempDirectory) is garbage-collected, TempDirectory.__del__ deletes work_path.path — the parent server's current working directory — causing os.getcwd() on the next _serving() call to fail permanently with FileNotFoundError while leaking the client socket FD.

Affected Location
  • Repository: apache/tvm (main, python/tvm/rpc/server.py:138-178)
Minimal Standalone Reproduction

Calling _serving() when the worker exits with code 139, triggering gc.collect(), and accepting a second session:

  • First session raises RuntimeError: Child process ... exited unsuccessfully with error code 139 and leaves s1.fileno() >= 0 (leaked FD).
  • os.getcwd() and the next _serving() call immediately fail with FileNotFoundError: [Errno 2] No such file or directory.
Suggested Fix

Wrap lines 142-177 in try: ... finally: os.chdir(old_cwd); work_path.remove(); sock.close(), and join() server_proc after terminate() on timeout.

Lingua principale
Python
Stelle
13.9k
Fork
4.1k
Merge medio
4g 22h
PR unite (30g)
22

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/tvm

Tutte le issue di apache/tvm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.