Open terlar opened 2 days ago
I'm pretty sure this was introduced by #409.
After some research, perhaps the pre-commit config require_serial: true
is what should be used instead. This will leave the parallelization to treefmt
. However, could potentially happen in multiple calls, if the filenames cannot fit in one invocation. But perhaps that is not a big issue.
Testing with this configuration the formatting was also faster. So seems relying on pre-commits parallelization slowed things down slightly.
Using --no-cache
is also considerable faster. So leaving out the cache seems to work well both with serial and non-serial execution. At least in this case. So perhaps when running as a pre-commit
hook cache should be disabled?
In this instance, --no-cache
is the simplest way of guaranteeing that multiple instances of treefmt
running at the same time do not conflict. However, on larger repos, the loss of the cache could have quite an impact.
require_serial
is a good idea, but as you said, there can still be concurrent invocations.
We could make the connection timeout for the db configurable. It's currently set to 1s
. In a pre-commit
hook, this could be increased to 10s
for example, and would ensure any concurrent invocations are queued.
Describe the bug
I just tried to update to
2.1.0
from2.0.5
. But now I start gettingI get this issue every time I try to run
treefmt
via pre-commit hook, if I don't have any cache. I have not been able to reproduce it runningtreefmt
directly. It seems to be becausepre-commit
is batching calls totreefmt
and there is some issue running multipletreefmt
in parallel and accessing this database?Of course it is fixable with
--no-cache
. But would be nice if I could use the cache when it is available.To Reproduce
Steps to reproduce the behavior:
https://github.com/terlar/pre-commit-treefmt-bug.git
nix develop
rm -r ~/.cache/treefmt
pre-commit run --all-files
Expected behavior
Running without failing with a timeout. Perhaps retry? Or add possibility to extend timeout or find another clever solution to the problem.
System information
Linux
Additional context
Only happens together with
pre-commit
or potentially also if you batch treefmt calls in other ways. I triggered this error with 100 files on one machine, but had to bump it on another one to trigger it. So it could potentially be that you cannot reproduce this depending on your hardware.