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

Ouverte
#21,083 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 3 jours

@Anurag1428 y travaille déjà.

Depuis le 29/11/2026.

  • #21085 par @Anurag1428 — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
python
Domaine
backend

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Python
Étoiles
13.9k
Forks
4.1k
Merge moyen
4 j 22 h
PR mergées (30 j)
22

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de apache/tvm

Toutes les issues de apache/tvm

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.