René's URL Explorer Experiment


Title: SymbolicReference.set_reference may not roll back properly on error · Issue #1669 · gitpython-developers/GitPython · GitHub

Open Graph Title: SymbolicReference.set_reference may not roll back properly on error · Issue #1669 · gitpython-developers/GitPython

X Title: SymbolicReference.set_reference may not roll back properly on error · Issue #1669 · gitpython-developers/GitPython

Description: SymbolicReference.set_reference contains this code, which is meant to attempt a transactional write: GitPython/git/refs/symbolic.py Lines 373 to 380 in a5a6464 ok = True try: fd.write(write_value.encode("utf-8") + b"\n") lfd.commit() ok ...

Open Graph Description: SymbolicReference.set_reference contains this code, which is meant to attempt a transactional write: GitPython/git/refs/symbolic.py Lines 373 to 380 in a5a6464 ok = True try: fd.write(write_value.e...

X Description: SymbolicReference.set_reference contains this code, which is meant to attempt a transactional write: GitPython/git/refs/symbolic.py Lines 373 to 380 in a5a6464 ok = True try: fd.write(write_value.e...

Opengraph URL: https://github.com/gitpython-developers/GitPython/issues/1669

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SymbolicReference.set_reference may not roll back properly on error","articleBody":"`SymbolicReference.set_reference` contains this code, which is meant to attempt a transactional write:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/a5a646494393478c65f26cd3a921f3505219d3e1/git/refs/symbolic.py#L373-L380\r\n\r\nHowever, because the `ok` flag is *initialized* to `True` instead of `False`--which strongly appears unintentional--it is always `True` even if the `ok = True` statement in the `try` block is not reached. Consequently, `lfd.rollback()` in the `finally` block is never called. This seems on first glance like a serious bug, but as detailed below I believe it might actually be quite minor in the context of what kind of cleanup GitPython generally [does or does not guarantee](https://github.com/gitpython-developers/GitPython?tab=readme-ov-file#leakage-of-system-resources).\r\n\r\nThis can be contrasted to another place where that pattern is used correctly:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/a5a646494393478c65f26cd3a921f3505219d3e1/git/index/base.py#L227-L233\r\n\r\nThis is very simple to fix, since it is sufficient to change `True` to `False` in the initial assignment. So most of the work to fix it would be figuring out where a regression test should go and how it should manage to produce a case where cleanup doesn't happen immediately.\r\n\r\n(Besides that simple fix, other fixes that also reduce the risk of such bugs coming back and allow the code to be simplified are possible. In particular, the `LockedFD` object represents a non-memory resource that always can and should be managed deterministically according to where control flow is, so it ought to implement the context manager protocol.)\r\n\r\nI am unsure if this bug causes any problems in practice. If I understand [`LockedFD`](https://github.com/gitpython-developers/gitdb/blob/master/gitdb/util.py#L269) correctly, the write that is not rolled back is to a temporary file separate from the real target, accessed through a file object specific to that `LockedFD` object. The lock file name is determined from the target file name, so if a separate attempt to write to the target is made, that could cause problems. `LockedFD` has a `__del__` method that should be called eventually and performs the rollback. On CPython, which has reference counting as its primary garbage collection strategy, cleanup would often happen immediately as a result... though not always, even in the absence of reference cycles, because, in exception handling, an exception object holds a reference to a traceback object which holds references to all stack frames in its call stack, through which local variables thus remain accessible until control leaves the handling `except` block.\r\n\r\nStill, it may be that this shall not be considered a bug--or at least not a bug of its own, or at least not a bug that merits a regression test accompanying its bugfix--on the grounds that **it might be considered a special case of the [Leakage of System Resources](https://github.com/gitpython-developers/GitPython?tab=readme-ov-file#leakage-of-system-resources) limitation** documented prominently in the readme. In support of this view, the third place in the code of GitPython where `ldf.rollback` is called uses a different pattern and its comments suggest that cleanup via `LockedFD.__del__` is considered acceptable to rely on:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/a5a646494393478c65f26cd3a921f3505219d3e1/git/refs/log.py#L261-L268\r\n\r\n(Interestingly, that is not exactly equivalent to the behavior of the `try`-`finally` pattern used in `git/index/base.py`. If it is intended to be, then it should catch `BaseException` rather than `Exception`.)","author":{"url":"https://github.com/EliahKagan","@type":"Person","name":"EliahKagan"},"datePublished":"2023-09-21T08:14:24.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/1669/GitPython/issues/1669"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2d05a527-fe10-e0a4-91e5-c6c296b99df5
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA4D2:1DF50E:885945:B6FD8D:69683790
html-safe-nonce874e36e6c2a192486adbbe58d6bcb54226f670eea5410340ab6a555f6000b26c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNEQyOjFERjUwRTo4ODU5NDU6QjZGRDhEOjY5NjgzNzkwIiwidmlzaXRvcl9pZCI6Ijc3MDk3NDA2MzA1MzQ1MzUwNTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac9966ce322df4b4d4a8912f191e378129906afd58a4fbdbf98ecd692ab8c8ecb7
hovercard-subject-tagissue:1906380130
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/gitpython-developers/GitPython/1669/issue_layout
twitter:imagehttps://opengraph.githubassets.com/5ad75d075c2d000c384182110fc6e769dc1f377961cb62891d007aae0703766f/gitpython-developers/GitPython/issues/1669
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/5ad75d075c2d000c384182110fc6e769dc1f377961cb62891d007aae0703766f/gitpython-developers/GitPython/issues/1669
og:image:altSymbolicReference.set_reference contains this code, which is meant to attempt a transactional write: GitPython/git/refs/symbolic.py Lines 373 to 380 in a5a6464 ok = True try: fd.write(write_value.e...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameEliahKagan
hostnamegithub.com
expected-hostnamegithub.com
Nonee25f416bb6d8a5f8624aad6cebc375ab2c50ac58f2175f32a7093325e66e5515
turbo-cache-controlno-preview
go-importgithub.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git
octolytics-dimension-user_id503709
octolytics-dimension-user_logingitpython-developers
octolytics-dimension-repository_id1126087
octolytics-dimension-repository_nwogitpython-developers/GitPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1126087
octolytics-dimension-repository_network_root_nwogitpython-developers/GitPython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release32212b8b3bddd6432b3b35d27c050b1c22bd8cca
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/gitpython-developers/GitPython/issues/1669#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F1669
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F1669
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=gitpython-developers%2FGitPython
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1669
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1669
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1669
gitpython-developers https://github.com/gitpython-developers
GitPythonhttps://github.com/gitpython-developers/GitPython
Please reload this pagehttps://github.com/gitpython-developers/GitPython/issues/1669
Notifications https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Fork 964 https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Star 5k https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Code https://github.com/gitpython-developers/GitPython
Issues 169 https://github.com/gitpython-developers/GitPython/issues
Pull requests 8 https://github.com/gitpython-developers/GitPython/pulls
Discussions https://github.com/gitpython-developers/GitPython/discussions
Actions https://github.com/gitpython-developers/GitPython/actions
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/gitpython-developers/GitPython/security
Please reload this pagehttps://github.com/gitpython-developers/GitPython/issues/1669
Insights https://github.com/gitpython-developers/GitPython/pulse
Code https://github.com/gitpython-developers/GitPython
Issues https://github.com/gitpython-developers/GitPython/issues
Pull requests https://github.com/gitpython-developers/GitPython/pulls
Discussions https://github.com/gitpython-developers/GitPython/discussions
Actions https://github.com/gitpython-developers/GitPython/actions
Security https://github.com/gitpython-developers/GitPython/security
Insights https://github.com/gitpython-developers/GitPython/pulse
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1669
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1669
#1675https://github.com/gitpython-developers/GitPython/pull/1675
SymbolicReference.set_reference may not roll back properly on errorhttps://github.com/gitpython-developers/GitPython/issues/1669#top
#1675https://github.com/gitpython-developers/GitPython/pull/1675
acknowledgedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22acknowledged%22
help wantedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22help%20wanted%22
v3.1.37 - Bugfixeshttps://github.com/gitpython-developers/GitPython/milestone/67
https://github.com/EliahKagan
https://github.com/EliahKagan
EliahKaganhttps://github.com/EliahKagan
on Sep 21, 2023https://github.com/gitpython-developers/GitPython/issues/1669#issue-1906380130
GitPython/git/refs/symbolic.pyhttps://github.com/gitpython-developers/GitPython/blob/a5a646494393478c65f26cd3a921f3505219d3e1/git/refs/symbolic.py#L373-L380
a5a6464https://github.com/gitpython-developers/GitPython/commit/a5a646494393478c65f26cd3a921f3505219d3e1
does or does not guaranteehttps://github.com/gitpython-developers/GitPython?tab=readme-ov-file#leakage-of-system-resources
GitPython/git/index/base.pyhttps://github.com/gitpython-developers/GitPython/blob/a5a646494393478c65f26cd3a921f3505219d3e1/git/index/base.py#L227-L233
a5a6464https://github.com/gitpython-developers/GitPython/commit/a5a646494393478c65f26cd3a921f3505219d3e1
LockedFDhttps://github.com/gitpython-developers/gitdb/blob/master/gitdb/util.py#L269
Leakage of System Resourceshttps://github.com/gitpython-developers/GitPython?tab=readme-ov-file#leakage-of-system-resources
GitPython/git/refs/log.pyhttps://github.com/gitpython-developers/GitPython/blob/a5a646494393478c65f26cd3a921f3505219d3e1/git/refs/log.py#L261-L268
a5a6464https://github.com/gitpython-developers/GitPython/commit/a5a646494393478c65f26cd3a921f3505219d3e1
acknowledgedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22acknowledged%22
help wantedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22help%20wanted%22
v3.1.37 - Bugfixeshttps://github.com/gitpython-developers/GitPython/milestone/67
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.