Bower install hangs on slow Git fetches with no timeout or cancellation option
0 reputation · 24 May 2025, 18:59 UTC
0 reputation · 24 May 2025, 18:59 UTC
On a project pinned to Bower 1.8.x, bower install delegates all package fetching to Git, and the CLI exposes no --timeout flag or documented cancellation mechanism. When a registry or Git remote responds slowly, the install simply blocks until the underlying Git process gives up on its own schedule, which varies by platform and Git configuration.
The goal is to bound install time in CI builds and recover cleanly when a fetch stalls, without leaving the Bower cache (~/.cache/bower) in a partially written state. Sending SIGINT or SIGKILL to the process appears to be the only way to abort, but it is unclear whether Bower performs any cleanup of in-progress downloads or lock state on termination.
Constraints: Bower is in maintenance mode, so a built-in fix is unlikely; any solution must work from the outside (wrapper scripts, process supervision) or via Git-level configuration such as http.lowSpeedLimit/http.lowSpeedTime, and it is uncertain how reliably those settings propagate through Bower's Git invocations.
bower install with an external timeout that avoids cache corruption?31275 reputation · 25 May 2025, 00:29 UTC
When a bower install is killed (SIGINT, SIGTERM or SIGKILL), Bower does not roll back the cache. The ~/.cache/bower directory may contain a half‑cloned Git repository or a partially extracted tarball. Subsequent bower install runs can then fail or reuse corrupted data. The safest approach is to purge the cache before retrying:
bower cache clean
Bower spawns Git without any explicit timeout flags. It relies on the environment that the Bower process inherits. Two ways to influence Git’s behaviour:
git config --global http.lowSpeedLimit 1000 and git config --global http.lowSpeedTime 30 are read by every Git invocation, including those spawned by Bower.GIT_CONFIG or GIT_CONFIG_NOSYSTEM before running Bower forces Git to load a custom config file. For example:GIT_CONFIG=/tmp/bower-git.cfg bower installCommand‑line flags such as --timeout are not forwarded by Bower, so they have no effect.
A proven pattern for CI is to wrap bower install with a timeout utility that sends a graceful SIGTERM and then cleans the cache if the command exits non‑zero. Example using the POSIX timeout command:
# Run for 30 seconds, then kill if still running
if ! timeout 30s bower install; then
echo "Bower install timed out – cleaning cache"
bower cache clean
exit 1
fi
On systems without timeout, a small shell wrapper can be used:
#!/usr/bin/env bash
set -e
# Start Bower in background
bower install &
BOWER_PID=$!
# Wait with a timeout
if ! wait $BOWER_PID; then
echo "Bower failed – cleaning cache"
bower cache clean
exit 1
fi
These approaches keep the cache in a clean state and provide a deterministic upper bound on install time.
After a timeout, run:
bower cache list
to confirm that no half‑downloaded packages remain. If any entries are marked incomplete, delete them manually or run bower cache clean again.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.