GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Race condition writing objects in LooseObjectDB · Issue #85 · gitpython-developers/gitdb

This repository was archived by the owner on Jul 26, 2026. It is now read-only.
This repository was archived by the owner on Jul 26, 2026. It is now read-only.

Race condition writing objects in LooseObjectDB #85

Copy link
Copy link
Closed
#91
Closed
Race condition writing objects in LooseObjectDB#85
#91
Copy link
Labels
acknowledgedhelp wanted

Description

@lordmauve
lordmauve
opened on Feb 13, 2023
Issue body actions

There's a TOCTTOU in LooseObjectDB when storing a new object, that causes storing an object to fail with FileExistsError:

   File "patch_tree.py", line 132, in write_tree
     return self.db.store(istream).binsha
   File ".venv/lib/python3.9/gitdb/db/git.py", line 77, in store
     return self._loose_db.store(istream)
   File ".venv/lib/python3.9/gitdb/db/loose.py", line 226, in store
     mkdir(obj_dir)
FileExistsError: [Errno 17] File exists: '/tmp/tmp.flUcclypOQ/objects/a0'

The problem code is

            if not isdir(obj_dir):
                mkdir(obj_dir)

and what is happening is

  1. isdir() returns False because the directory does not exist at that moment
  2. The directory is created in another thread
  3. mkdir() fails with FileExistsError

This can be avoided by using an EAFP pattern, e.g.

with contextlib.suppress(FileExistsError):
    mkdir(obj_dir)

Activity

  1. lordmauve
    changed the title [-]Race condition in LooseDB[/-] [+]Race condition in LooseObjectDB[/+] on Feb 13, 2023
  2. lordmauve
    changed the title [-]Race condition in LooseObjectDB[/-] [+]Race condition writing objects in LooseObjectDB[/+] on Feb 13, 2023
  3. Byron
    added
    acknowledged
    help wanted
    on Feb 14, 2023
  4. Byron commented on Feb 14, 2023

    @Byron
    Byron
    on Feb 14, 2023
    Member
    More actions

    Thanks for reporting and for providing a suggestion for a fix. A PR is definitely welcome.

  5. Byron
    closed this as completedin #91on Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledgedhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.