Title: Race condition writing objects in LooseObjectDB · Issue #85 · gitpython-developers/gitdb · GitHub
Open Graph Title: Race condition writing objects in LooseObjectDB · Issue #85 · gitpython-developers/gitdb
X Title: Race condition writing objects in LooseObjectDB · Issue #85 · gitpython-developers/gitdb
Description: 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/...
Open Graph Description: 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)...
X Description: 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....
Opengraph URL: https://github.com/gitpython-developers/gitdb/issues/85
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Race condition writing objects in LooseObjectDB","articleBody":"There's a TOCTTOU in LooseObjectDB when storing a new object, that causes storing an object to fail with `FileExistsError`:\r\n\r\n```\r\n File \"patch_tree.py\", line 132, in write_tree\r\n return self.db.store(istream).binsha\r\n File \".venv/lib/python3.9/gitdb/db/git.py\", line 77, in store\r\n return self._loose_db.store(istream)\r\n File \".venv/lib/python3.9/gitdb/db/loose.py\", line 226, in store\r\n mkdir(obj_dir)\r\nFileExistsError: [Errno 17] File exists: '/tmp/tmp.flUcclypOQ/objects/a0'\r\n```\r\n\r\n[The problem code](https://github.com/gitpython-developers/gitdb/blame/master/gitdb/db/loose.py#L225) is\r\n\r\n```python\r\n if not isdir(obj_dir):\r\n mkdir(obj_dir)\r\n```\r\n\r\nand what is happening is\r\n\r\n1. `isdir()` returns `False` because the directory does not exist at that moment\r\n2. The directory is created in another thread\r\n3. `mkdir()` fails with `FileExistsError`\r\n\r\nThis can be avoided by using an EAFP pattern, e.g.\r\n\r\n```python\r\nwith contextlib.suppress(FileExistsError):\r\n mkdir(obj_dir)\r\n```","author":{"url":"https://github.com/lordmauve","@type":"Person","name":"lordmauve"},"datePublished":"2023-02-13T14:22:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/85/gitdb/issues/85"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3ae68594-3b69-9c61-e821-94b8959ad7da |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8CC:2C5AFC:21A66C2:2FA7D98:69691690 |
| html-safe-nonce | 729db2c28ebc0e002723f6091f9a1c3023f97cb0f407e4a84bf2edec64170d53 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOENDOjJDNUFGQzoyMUE2NkMyOjJGQTdEOTg6Njk2OTE2OTAiLCJ2aXNpdG9yX2lkIjoiNzgwNTc0NzM0NDQ2NzEwNTQyNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 819f9956bd8c0a230675a4ce6354d55abf3a82e43fca26f719c0b15856c1393a |
| hovercard-subject-tag | issue:1582445326 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/gitpython-developers/gitdb/85/issue_layout |
| twitter:image | https://opengraph.githubassets.com/649436857bf74f8c1c5e570aab529b9cd2bf3d61ede22c417d29588f76fcd4e7/gitpython-developers/gitdb/issues/85 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/649436857bf74f8c1c5e570aab529b9cd2bf3d61ede22c417d29588f76fcd4e7/gitpython-developers/gitdb/issues/85 |
| og:image:alt | 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)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lordmauve |
| hostname | github.com |
| expected-hostname | github.com |
| None | afd5814870f8609d217a32dd3bccc05a5df5f5699df4d458c242e80fdfddcc2e |
| turbo-cache-control | no-preview |
| go-import | github.com/gitpython-developers/gitdb git https://github.com/gitpython-developers/gitdb.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126093 |
| octolytics-dimension-repository_nwo | gitpython-developers/gitdb |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126093 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/gitdb |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 572e69339f2401a569f15071214cbbee314ea8bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width