bazel: Bazel is stuck fetching external repositories

Description of the bug:

We have reports of Bazel consistently hanging during fetching of external repositories. Particular, those consumed with git_override / git_repository.

Which category does this issue belong to?

No response

What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

I do not have a reproducible example or a way to consistently reproduce this. When this happens it’s been reported that it’ll consistently hang even on server restarts. The only thing that helps is restarting the users machine until they eventually hit it again.

Which operating system are you running Bazel on?

macOS 14

What is the output of bazel info release?

release 6.5.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What’s the output of git remote get-url origin; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

I’ve found some other threads in Slack and issues on GitHub related to hanging but nothing that seems like this.

Any other information, logs, or outputs that you want to share?

Some information about our environment:

  • We are using arm64 machines
  • Xcode 15.1 toolchains
  • Bzlmod enabled (without lockfile)

Our reporter also managed collect 3 jstack traces when the Bazel command was hung. I’ve attached those below. bazel_jstack_trace.log

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (16 by maintainers)

Commits related to this issue

Most upvoted comments

So I believe (with the testing I’ve done) that https://github.com/bazelbuild/bazel/pull/23626 solves this issue within git_worker.

I performed tests by spawning many file watchers using the fswatch tool, using a released Bazel version 7.3.1 when running bazel fetch in the examples/lots_of_repos directory of the branch: https://github.com/cgrindel/rules_swift_package_manager/tree/luis/lots-of-repo-example I was able to consistently reproduce stuck fetches.

I confirmed that building //src:bazel and using that instead consistently allows all fetches to continue and I ran into no hangs during the process.


#!/bin/bash

# Number of monitors to create
NUM_MONITORS=100  # Adjust based on your stress test needs

# Directory to monitor (can be the same or different for each monitor)
MONITOR_DIR="/tmp/fsmonitor-test"

# Create the directory if it doesn't exist
mkdir -p "$MONITOR_DIR"

# Array to store process IDs of background fswatch processes
declare -a PIDS

# Function to create and run a file system monitor
create_monitor() {
  local dir=$1
  fswatch "$dir" >/dev/null &
  PIDS+=($!)  # Store the process ID
}

# Create the specified number of monitors
for i in $(seq 1 $NUM_MONITORS); do
  create_monitor "$MONITOR_DIR"
  
  # Optionally, introduce a slight delay to avoid overwhelming the system too quickly
  sleep 0.1
done

echo "Created $NUM_MONITORS file system monitors."


# Function to clean up by killing all background processes
cleanup() {
  echo "Cleaning up monitors..."
  for pid in "${PIDS[@]}"; do
    kill "$pid" 2>/dev/null
  done
  echo "All monitors terminated."
}

# Trap script exit (Ctrl+C or normal exit) to ensure cleanup happens
trap cleanup EXIT

# Keep the script running to simulate long-running monitors
echo "Press Ctrl+C to stop the script and clean up the monitors."
while true; do
  sleep 10  # Keep the script alive indefinitely
done

Thanks for the reply. I also found this discussion. I am trying the –experimental_worker_for_repo_fetching set to off.

since it sounds like this is some problem with git, I’m going to go ahead and close this. Feel free to reopen if this is actually Bazel-related.

just from a brief look at the 3 stack traces, they seem to be hung on different things. I couldn’t immediately tell what the first two are about, but the third one seems to be waiting for the git subprocess to exit. Is the git process still alive when you took the stack trace?