realpath has a race condition which might cause it to throw spurious exceptions

Open
#97,566 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start with the realpath reproduction linked in the issue and trace the islink/readlink sequence described there. Confirm the failure when a symlink is deleted between those operations; done means realpath no longer raises a spurious exception in that race, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Description

3.10 3.11 3.12 extension-modules type-bug

Bug report

realpath tests if a file is a symlink using islink, which just returns False if the file does not exist. But then uses readlink a bit later to test the source of the link, which throws an exception if the file does not exists. If the file is a symlink and is deleted between islink and readlink, we get a spurious exception.

This reproduces the error using code copy-pasted from Python 3.9: https://gist.github.com/bitonic/e0977aaa674523a9ffe0e77a96cd6cc7 .

Your environment

  • CPython 3.9
  • ArchLinux x86_64
Dominant language
Python
Stars
77.2k
Forks
36k
Avg merge
1d 9h
Merged PRs (30d)
558

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/cpython

All issues in python/cpython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.