Skip to content

Fix: avoid indefinite Sphinx build freeze from unbounded git log call#1636

Open
suhr25 wants to merge 5 commits intoQubesOS:mainfrom
suhr25:fix/last-edition-subprocess-timeout
Open

Fix: avoid indefinite Sphinx build freeze from unbounded git log call#1636
suhr25 wants to merge 5 commits intoQubesOS:mainfrom
suhr25:fix/last-edition-subprocess-timeout

Conversation

@suhr25
Copy link
Copy Markdown

@suhr25 suhr25 commented Feb 25, 2026

Summary

This PR fixes a blocking issue in _ext/last_edition.py where a git log subprocess is executed without a timeout inside the html_page_context hook.

Since html_page_context runs once per page during Sphinx builds, the following code path is executed repeatedly:

last_datetime_raw = subprocess.check_output(
    (
        "git",
        "--git-dir",
        git_dir,
        "log",
        "-1",
        "--pretty=format:%ci",
        "--",
        f"{pagename}{context['page_source_suffix']}",
    )
).decode()

Without a timeout, any delay/hang in git (repo lock, concurrent git operations, slow filesystem, etc.) can block the entire Sphinx build indefinitely. This is especially noticeable with sphinx-autobuild, where one stuck build prevents subsequent rebuilds.

Fix

The subprocess call is now bounded with a timeout and handles timeout failures gracefully:

last_datetime_raw = subprocess.check_output(
    (...),
    timeout=5,
).decode()
except (subprocess.CalledProcessError, subprocess.TimeoutExpired):
    return

Key improvements

  • Prevents indefinite blocking of Sphinx builds
  • Ensures builds continue even if git is slow/unavailable
  • Gracefully skips last_edition metadata for affected pages
  • Minimal, localized change; normal fast-path remains unchanged

Verification

  • Ran sphinx-autobuild locally and confirmed rebuilds continue under simulated git delays (e.g., temporary repo lock / slow response)
  • Confirmed normal behavior is unchanged when git log executes quickly

Prevent sphinx-autobuild from hanging indefinitely when git is slow
or locked. Fall back to last_edition_datetime=None on timeout.

Signed-off-by: suhr25 <suhridmarwah07@gmail.com>
@suhr25
Copy link
Copy Markdown
Author

suhr25 commented Feb 25, 2026

Hi @unman ,
All checks are passing and this fix prevents sphinx autobuild from hanging due to unbounded git calls.
Would appreciate a quick review when you have time, thanks!

Copy link
Copy Markdown
Contributor

@parulin parulin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be even better to only include this extension in specific situations, in conf.py:

if os.environ.get('READTHEDOCS') or os.environ.get('QUBES_DOC_FULL_BUILD'):
    extensions.append('last_edition')

Comment thread _ext/last_edition.py Outdated
Comment thread _ext/last_edition.py Outdated
…r handling

- Reduce default subprocess timeout from 5s to 1s to avoid accumulating
  delay across ~190 pages; make it overridable via QUBES_LAST_EDITION_TIMEOUT
- Extend exception handling to also catch FileNotFoundError, PermissionError,
  and OSError so any git invocation failure is silently ignored
- Gate the extension in conf.py behind READTHEDOCS or QUBES_DOC_FULL_BUILD
  env vars to avoid running git on every plain local build
@suhr25
Copy link
Copy Markdown
Author

suhr25 commented Feb 27, 2026

Hi @parulin @unman,

I’ve addressed the feedback: reduced the timeout (now configurable via env var), added the missing exception handling, and gated last_edition in conf.py to only run on READTHEDOCS / full builds.
Thanks!

@parulin
Copy link
Copy Markdown
Contributor

parulin commented Feb 27, 2026

Ok, nice. Sorry, but I think that now, we also need to document those variables, maybe in /developer/general/how-to-edit-the-rst-documentation:Building the rST documentation locally... It could also be part of another PR.

@suhr25
Copy link
Copy Markdown
Author

suhr25 commented Feb 27, 2026

Hi @parulin @unman @maiska,
Thanks for the suggestion! I’ve added documentation for the new environment variables in
developer/general/how-to-edit-the-rst-documentation.rst.

Please take a look.

@parulin
Copy link
Copy Markdown
Contributor

parulin commented Feb 28, 2026

No need to mention everyone.

I made a PR to your personal repo to avoid more work for you. I will try to merge our two versions and update it.

* add a section about building with environment variables
* rewrite part of the last_edition extension section
* use `QUBES_DOC_` prefix to be consistent
* minor typos in how-to-edit-the-rst-documentation
@parulin
Copy link
Copy Markdown
Contributor

parulin commented Feb 28, 2026

Just a few tips about the documentation style guide:

@suhr25
Copy link
Copy Markdown
Author

suhr25 commented Feb 28, 2026

Thanks for the improvements and the style guidance. I will align with the no hardwrap rule going forward.

Add documentation for build environment variables
@suhr25
Copy link
Copy Markdown
Author

suhr25 commented Feb 28, 2026

@parulin
I merged the updates from the PR you opened on my fork . Please take another look.
Thanks!

@suhr25 suhr25 requested a review from parulin February 28, 2026 12:59
@parulin
Copy link
Copy Markdown
Contributor

parulin commented Feb 28, 2026

There is nothing new to review for me.

@suhr25
Copy link
Copy Markdown
Author

suhr25 commented Feb 28, 2026

Let me know if anything else is needed from my side.

@suhr25
Copy link
Copy Markdown
Author

suhr25 commented Mar 1, 2026

@parulin,
I updated the PR to follow the documentation style guide: removed unused .. _label: anchors and ensured paragraphs are not hard wrapped. The functional change remains the same .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants