Skip to content

Conversation

@jmelahman
Copy link
Contributor

@jmelahman jmelahman commented Dec 4, 2025

I have a global post-checkout hook installed. I think what is happening is when I install hooks in my repository, prek then clones and checks out the hook repository. This checkout then triggers prek in the hook repository via the global post-checkout hook which then waits on the parent prek running in my repository to release (which it won't) and hangs indefinitely.

Also, I think it's veryyy rare anyone would want to run hooks here and for the most part, people don't want the install to error because the upstream hooks fail. Also, they (imo) needlessly slow this initialization anyways.

I confirmed locally this avoids the hanging.


Relevant logs from the issue,

$ cat prek.log 
2025-12-04T18:22:31.344962Z DEBUG prek: 0.2.19 (bdc40e36a 2025-11-26)
2025-12-04T18:22:31.345002Z DEBUG Args: ["prek", "run", "--verbose", "--log-file", "prek.log", "--refresh"]
2025-12-04T18:22:31.347216Z TRACE get_root: close time.busy=2.18ms time.idle=3.82µs
2025-12-04T18:22:31.347269Z DEBUG Git root: /home/jamison/code/onyx
2025-12-04T18:22:31.347287Z TRACE Executing `/usr/bin/git ls-files --unmerged`
2025-12-04T18:22:31.349930Z DEBUG Found workspace root at `/home/jamison/code/onyx`
2025-12-04T18:22:31.349992Z TRACE Include selectors: ``
2025-12-04T18:22:31.350006Z TRACE Skip selectors: ``
2025-12-04T18:22:31.350040Z DEBUG discover{root="/home/jamison/code/onyx" config=None refresh=true}: Performing fresh workspace discovery
2025-12-04T18:22:31.350096Z TRACE discover{root="/home/jamison/code/onyx" config=None refresh=true}:list_submodules{git_root="/home/jamison/code/onyx"}: close time.busy=6.32µs time.idle=1.45µs
2025-12-04T18:22:31.352610Z DEBUG Loading project configuration path=.pre-commit-config.yaml
2025-12-04T18:22:31.355411Z TRACE read_config{path="/home/jamison/code/onyx/.pre-commit-config.yaml"}: close time.busy=2.69ms time.idle=11.9µs
2025-12-04T18:22:31.364110Z TRACE discover{root="/home/jamison/code/onyx" config=None refresh=true}: close time.busy=14.1ms time.idle=4.47µs
2025-12-04T18:22:31.364208Z TRACE Executing `/usr/bin/git diff --exit-code --name-only -z /home/jamison/code/onyx/.pre-commit-config.yaml`
2025-12-04T18:22:31.368126Z TRACE Checking lock resource="store" path=/home/jamison/.cache/prek/.lock
2025-12-04T18:22:31.368171Z DEBUG Acquired lock resource="store"
2025-12-04T18:22:31.369430Z DEBUG Cloning repo target=/home/jamison/.cache/prek/scratch/.tmpl1tTJe repo=https://github.com/pre-commit/[email protected]
2025-12-04T18:22:31.369496Z TRACE Executing `/usr/bin/git -c init.defaultObjectFormat= init --template= /home/jamison/.cache/prek/scratch/.tmpl1tTJe`
2025-12-04T18:22:31.370551Z DEBUG Cloning repo target=/home/jamison/.cache/prek/scratch/.tmpD4S3dZ repo=https://github.com/psf/[email protected]
2025-12-04T18:22:31.370570Z TRACE Executing `/usr/bin/git -c init.defaultObjectFormat= init --template= /home/jamison/.cache/prek/scratch/.tmpD4S3dZ`
2025-12-04T18:22:31.370970Z DEBUG Cloning repo target=/home/jamison/.cache/prek/scratch/.tmpq8h1tW repo=https://github.com/PyCQA/[email protected]
2025-12-04T18:22:31.370985Z TRACE Executing `/usr/bin/git -c init.defaultObjectFormat= init --template= /home/jamison/.cache/prek/scratch/.tmpq8h1tW`
2025-12-04T18:22:31.379100Z TRACE Executing `cd /home/jamison/.cache/prek/scratch/.tmpq8h1tW && /usr/bin/git remote add origin https://github.com/PyCQA/autoflake`
2025-12-04T18:22:31.379285Z TRACE Executing `cd /home/jamison/.cache/prek/scratch/.tmpl1tTJe && /usr/bin/git remote add origin https://github.com/pre-commit/pre-commit-hooks`
2025-12-04T18:22:31.379446Z TRACE Executing `cd /home/jamison/.cache/prek/scratch/.tmpD4S3dZ && /usr/bin/git remote add origin https://github.com/psf/black`
2025-12-04T18:22:31.381090Z TRACE Executing `cd /home/jamison/.cache/prek/scratch/.tmpq8h1tW && /usr/bin/git fetch origin v2.3.1 --depth=1`
2025-12-04T18:22:31.381237Z TRACE Executing `cd /home/jamison/.cache/prek/scratch/.tmpl1tTJe && /usr/bin/git fetch origin v4.6.0 --depth=1`
2025-12-04T18:22:31.381393Z TRACE Executing `cd /home/jamison/.cache/prek/scratch/.tmpD4S3dZ && /usr/bin/git fetch origin 25.1.0 --depth=1`
2025-12-04T18:22:32.799952Z TRACE Executing `cd /home/jamison/.cache/prek/scratch/.tmpl1tTJe && /usr/bin/git checkout FETCH_HEAD`
2025-12-04T18:22:32.823903Z TRACE Executing `cd /home/jamison/.cache/prek/scratch/.tmpq8h1tW && /usr/bin/git checkout FETCH_HEAD`
2025-12-04T18:22:33.185641Z TRACE Executing `cd /home/jamison/.cache/prek/scratch/.tmpD4S3dZ && /usr/bin/git checkout FETCH_HEAD`

@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.72%. Comparing base (b5be7c6) to head (b1a595d).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1192      +/-   ##
==========================================
- Coverage   89.73%   89.72%   -0.01%     
==========================================
  Files          78       78              
  Lines       14767    14773       +6     
==========================================
+ Hits        13251    13255       +4     
- Misses       1516     1518       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@j178 j178 changed the title fix: deadlock on hook-install w/ post-checkout hook Prevent post-checkout deadlock when cloning repos Dec 5, 2025
@j178 j178 added the bug Something isn't working label Dec 5, 2025
@github-actions
Copy link

github-actions bot commented Dec 5, 2025

📦 Cargo Bloat Comparison

Binary size change: +0.00% (16.7 MiB → 16.7 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text     Size          Crate Name
 0.6%   1.3% 104.8KiB          prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.6%   1.3% 100.4KiB           prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7%  54.6KiB           prek prek::archive::unpack::{{closure}}
 0.3%   0.7%  53.0KiB             h2 h2::proto::connection::Connection<T,P,B>::poll
 0.3%   0.6%  48.6KiB           prek prek::run::{{closure}}
 0.2%   0.5%  40.0KiB           prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.5%  39.2KiB          prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.2%   0.5%  37.3KiB regex_automata regex_automata::meta::strategy::new
 0.2%   0.4%  35.2KiB           prek prek::workspace::Workspace::discover
 0.2%   0.4%  31.4KiB           std? <core::marker::PhantomData<T> as serde_core::de::DeserializeSeed>::deserialize
 0.2%   0.4%  30.1KiB           prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4%  28.8KiB           prek prek::languages::node::installer::NodeInstaller::install::{{closure}}
 0.2%   0.4%  28.1KiB             h2 h2::proto::connection::DynConnection<B>::recv_frame
 0.2%   0.3%  27.6KiB           prek prek::identify::by_extension::{{closure}}
 0.1%   0.3%  25.1KiB           prek prek::main
 0.1%   0.3%  24.4KiB     hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.3%  24.4KiB           std? <core::marker::PhantomData<T> as serde_core::de::DeserializeSeed>::deserialize
 0.1%   0.3%  24.3KiB     hyper_util hyper_util::client::legacy::client::Client<C,B>::connect_to::{{closure}}::{{closure}}::{{closure}}
 0.1%   0.3%  24.2KiB           prek prek::hook::HookBuilder::build::{{closure}}
 0.1%   0.3%  23.9KiB          hyper hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_loop
41.1%  88.8%   6.8MiB                And 10633 smaller methods. Use -n N to show more.
46.3% 100.0%   7.7MiB                .text section size, the file size is 16.7MiB

Base Branch Results

 File  .text     Size          Crate Name
 0.6%   1.3% 104.8KiB          prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.6%   1.3% 100.4KiB           prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7%  54.6KiB           prek prek::archive::unpack::{{closure}}
 0.3%   0.7%  53.0KiB             h2 h2::proto::connection::Connection<T,P,B>::poll
 0.3%   0.6%  48.6KiB           prek prek::run::{{closure}}
 0.2%   0.5%  40.0KiB           prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.5%  39.2KiB          prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.2%   0.5%  37.3KiB regex_automata regex_automata::meta::strategy::new
 0.2%   0.4%  35.2KiB           prek prek::workspace::Workspace::discover
 0.2%   0.4%  31.4KiB           std? <core::marker::PhantomData<T> as serde_core::de::DeserializeSeed>::deserialize
 0.2%   0.4%  30.1KiB           prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4%  28.8KiB           prek prek::languages::node::installer::NodeInstaller::install::{{closure}}
 0.2%   0.4%  28.1KiB             h2 h2::proto::connection::DynConnection<B>::recv_frame
 0.2%   0.3%  27.6KiB           prek prek::identify::by_extension::{{closure}}
 0.1%   0.3%  25.1KiB           prek prek::main
 0.1%   0.3%  24.4KiB     hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.3%  24.4KiB           std? <core::marker::PhantomData<T> as serde_core::de::DeserializeSeed>::deserialize
 0.1%   0.3%  24.3KiB     hyper_util hyper_util::client::legacy::client::Client<C,B>::connect_to::{{closure}}::{{closure}}::{{closure}}
 0.1%   0.3%  24.2KiB           prek prek::hook::HookBuilder::build::{{closure}}
 0.1%   0.3%  23.9KiB          hyper hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_loop
41.1%  88.8%   6.8MiB                And 10633 smaller methods. Use -n N to show more.
46.3% 100.0%   7.7MiB                .text section size, the file size is 16.7MiB

@j178
Copy link
Owner

j178 commented Dec 5, 2025

Thanks! I think the better fix is just to set the internal env var PREK_INTERNAL__SKIP_POST_CHECKOUT.

@j178 j178 merged commit 20dbb99 into j178:master Dec 5, 2025
21 checks passed
@jmelahman jmelahman deleted the jamison/hook-init-deadlock branch December 5, 2025 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants