惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX - 技术
D
DataBreaches.Net
阮一峰的网络日志
阮一峰的网络日志
Recent Announcements
Recent Announcements
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
K
Kaspersky official blog
F
Fortinet All Blogs
GbyAI
GbyAI
Forbes - Security
Forbes - Security
The Cloudflare Blog
博客园 - 司徒正美
博客园_首页
量子位
Schneier on Security
Schneier on Security
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Proofpoint News Feed
N
News | PayPal Newsroom
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
T
Tor Project blog
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
Jina AI
Jina AI
Help Net Security
Help Net Security
T
Threat Research - Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cybersecurity and Infrastructure Security Agency CISA
Project Zero
Project Zero
N
News and Events Feed by Topic
I
Intezer
B
Blog
美团技术团队
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 最新话题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
AWS News Blog
AWS News Blog
T
Tailwind CSS Blog
The Last Watchdog
The Last Watchdog
雷峰网
雷峰网
有赞技术团队
有赞技术团队

The Practical Developer

The Libuv Thread Pool Trap: Why Node.js Async APIs Stall Under Load Postgres Covering Indexes with INCLUDE: Eliminate Heap Fetches on Read-Heavy Workloads Postgres DISTINCT ON: The Fastest Way to Get the Latest Row Per Group Postgres Transaction Isolation: The Anomalies Your App Actually Faces in Production Linux TCP Tuning for Node.js Microservices: The Kernel Settings That Stop Silent Connection Drops Under Load Postgres HOT Updates and Fillfactor: Why Not All Writes Are Created Equal Database Connection Pool Leaks: Finding the Promise That Never Returns Its Seat Linux OOM Killer in Production: Why Your Node.js Containers Die Without a Stack Trace Postgres Materialized Views: Refresh Strategies That Do Not Lock Your Dashboards API Dependency Health Checks: Why /health Is Not Enough Authorization with Zanzibar Tuples: How Google Manages Permissions and How To Build the Same Check in Node.js Postgres Advisory Locks: The 20-Character Primitive That Replaces Redis for Coordination Dead Letter Queues: The Message Queue Pattern That Saves You at 2 a.m. File Descriptor Exhaustion: The Kernel Limit That Silently Drops Node.js Connections Graceful Degradation: The Pattern That Turns Total Outages into Partial Success PostgreSQL Full-Text Search: Dropping Elasticsearch for 90% of Use Cases S3 Presigned Multipart Uploads: Stop Your API Server from Being a File Upload Bottleneck MessagePack vs JSON: The Binary Serialization Switch That Cut Our Internal RPC Overhead by 40% DNS Caching in Node.js: The Silent Cause of Production Latency Spikes Reliable Cron Jobs: The Pattern That Stops Double Runs, Missed Executions, And The 2 AM Page GraphQL Query Complexity: Stop the OOM Query Before It Reaches Your Resolver Node.js Event Loop Lag: The Hidden Metric Behind Random Latency Spikes API Request Validation with Zod: The Schema That Catches Bad Input Before It Corrupts Your Database Load Shedding in Node.js: How to Reject Traffic Before You Drown Request Hedging: Cut Tail Latency In Half Without Overprovisioning Node.js Garbage Collection Tuning: Stop Letting V8 Pause Your Event Loop Node.js Server Timeouts: The Settings That Stop Slow Clients from Holding Sockets Hostage Postgres BRIN Indexes: The Time-Series Secret That Shrinks Indexes by 99% Event Sourcing with PostgreSQL: The Pragmatic 80% Solution Node.js Cluster Mode: Scaling the Event Loop Across CPU Cores Postgres Partial Indexes: Stopping Soft Deletes from Ruining Your Query Performance Request Coalescing with the Singleflight Pattern: Stop Drowning Your Database on Every Cache Miss The Bulkhead Pattern: Why One Slow Endpoint Should Not Drown Your Whole Service Node.js AsyncLocalStorage: End-to-End Request Context Without the Propagation Hell Postgres Deadlocks: Logging the Victim, Reproducing the Race, and Fixing the Lock Order Your Node.js HTTP Client Is the Bottleneck: Connection Pool Tuning That Works Optimistic Locking in Postgres: Stop Losing Data to Race Conditions Postgres Read Replicas: Stop Serving Stale Data to Your Users Cursor Pagination: Why Offset Queries Explode at Scale and How to Fix Them Node.js Worker Threads: 60 Lines That Stop a CSV Upload from Timing Out Every Other Request Reliable Webhook Delivery: Architecture for Outbound HTTP You Can Trust Request Timeouts and Deadline Propagation: Stop the Chain of Slowness Advanced Security Practices in Node.js Graceful Shutdown in Node.js: The 40 Lines That Stop 502s During Deploys Finding Node.js Memory Leaks with Heap Snapshots Idempotency Keys in 30 Lines: Stop Your Webhook From Charging Customers Twice Backpressure In Node.js: The Fix For Slow-Motion Queue Meltdowns Retries Done Right: Jitter, Budgets, and the Stampede You Did Not See Coming The Cache Stampede: Why Your "Just Add Redis" Layer Crashes Postgres at 3 a.m. Postgres SKIP LOCKED: An 80-Line Job Queue You Can Run Without Redis Stop Doing Work Nobody Wants: AbortController in Node.js, Done Right The N+1 Query Problem: We Found 23 In One Codebase And Killed Every One I Tried 5 AI Coding Tools for a Month. Here Is What I Actually Use CI/CD From Zero to Production in 30 Minutes With GitHub Actions Node.js vs Bun vs Deno: Which Runtime Should You Pick in 2025? Kubernetes Resource Requests And Limits: The Numbers That Decide If Your Cluster Is Stable The Three Pillars of Observability Are A Myth: What Actually Matters In Production pnpm Vs npm Vs yarn Vs Bun For Monorepos: Which One Earns The Migration In 2024 JSONB Indexing In Postgres: GIN Vs Expression Indexes, And When Each Is The Right Choice A Code Review Checklist That Ends The Same Three Arguments Every Sprint gRPC Vs REST In 2024: When The Switch Pays For Itself React Suspense For Data Fetching: The Pattern That Replaces Half Your Loading State Code The Five-Stage Rollout: How To Ship A Risky Change Without Holding Your Breath GitHub Actions In A Monorepo: Caching, Path Filters, And Secret Boundaries That Actually Work The Blameless Postmortem That Actually Improves Things: A Template And Six Hard-Won Rules Recursive CTEs In Postgres: How To Query A Tree Without N Round Trips Node.js Streams: When They Actually Help, And When They Just Add Complexity Playwright Vs Cypress In 2024: The Honest Comparison Of Which One Earns The Test Time React Server Components: The Mental Model That Makes The "use client" Boundary Obvious Pod Disruption Budgets: The K8s Object That Keeps Your Service Up During Cluster Maintenance Postgres LISTEN/NOTIFY: The Pub/Sub You Already Have And Are Not Using Chaos Engineering Starter Kit: The Five Drills That Don't Need Netflix-Scale Spec-Driven API Development With OpenAPI: How To Stop Drifting From Your Docs Saga Pattern vs Two-Phase Commit: Distributed Transactions Without The Lies Kubernetes Autoscaling Beyond CPU: The Custom-Metric HPA Pattern That Actually Works Postgres Partitioning For Time-Series: The Boring Setup That Saves Your Database Distributed Locks With Redis: An Honest Look At Redlock And When You Don't Need It HTTP/2 vs HTTP/3: What Actually Changes For Your App, And What Doesn't Image Optimization For The Web In 2023: srcset, AVIF, And The Lighthouse Score You Actually Want Kafka vs RabbitMQ: A Decision Tree That Doesn't Hate You UUID vs Bigint Primary Keys In Postgres: The Index Math That Decides For You Flame Graphs: How To Find The Slow Function In 30 Seconds Without Profiling Theatre Postgres Streaming Vs. Logical Replication: Which One Solves Your Actual Problem ESLint Rules That Earn Their Keep: The Twelve I Enable On Every Project Pre-Commit Hooks That Pay For Themselves: Husky, lint-staged, And The Five Rules That Stick Zero-Downtime Database Migrations: The Six-Step Pattern That Rules Them All Circuit Breakers In Node.js: 50 Lines That Stop A Failing Dependency From Taking Down Your Service Postgres VACUUM Is Not Magic: How Your Hot Table Bloats To 80GB And How To Fix It Kubernetes Liveness And Readiness Probes: The Difference That Causes Half Your Outages Rate Limiting In Production: A Token Bucket In 30 Lines Of Redis The Outbox Pattern: How To Stop Losing Events When Postgres And Kafka Disagree Load Testing With k6: The Three Scenarios That Find Real Bugs (Not Synthetic Numbers) Postgres Row-Level Security For Multi-Tenant Apps: The Pattern That Stops You From Leaking Data Rebase vs. Merge: The Team Policy That Ends The Argument Forever OpenTelemetry in Node.js: Distributed Tracing That Actually Helps During an Incident Feature Flags That Pay Rent: The 4 Flag Types And When To Delete Each ETag, Last-Modified, and the Caching Headers Most APIs Get Wrong Connection Pooling Without the Cargo Cult: pgbouncer in 100 Lines of Config JSONB Is Not a Schema: When To Reach For It in Postgres, And When To Stop Bash Strict Mode: The Three Lines That Stop Your Deploy Script From Lying To You
Git Bisect: The Automated Binary Search That Finds Breaking Commits in Minutes
The Practica · 2026-05-18 · via The Practical Developer

Your deploy pipeline went green at 2 p.m. By 3 p.m. the error rate graph is a staircase. The on-call engineer rolls back to the previous release and the fire goes out, but the commit that caused it is still somewhere in the two hundred changes that landed since Monday. Finding it by hand means checking out an old commit, building, running the reproduction, noting the result, and repeating. At ten minutes per iteration, that is thirty-three hours of worst-case work. Most teams do not have thirty-three hours. They have a blameless postmortem in the morning and a promise to “add more tests.”

Git bisect is the tool that turns that linear nightmare into a binary search. Instead of testing every commit, you test log2(N) commits. Two hundred changes becomes eight tests. And if you write a small script that can detect the bug automatically, git bisect run does those eight tests while you make coffee. This post is the exact workflow, the script template, the edge cases that trip people up, and the CI integration that turns bisect from a firefighting tool into a preventative one.

The shape of the failure

You know the pattern. A refactor landed on Tuesday. A dependency upgrade landed Wednesday. A feature branch merged Thursday. The rollback fixed the symptom, but the root cause could be any of those three, or an interaction between two of them. The ticket says “investigate regression,” which really means “find the commit so we can revert or patch it without reverting the entire release.”

The naive approach is to check out the commit from just before the release, verify it is good, then walk forward one commit at a time. That is O(n). With a large merge commit history, it is also confusing. Merge commits have two parents, and “forward” is not a single line. You end up retesting the same code paths through different history shapes, and half your time is spent figuring out which commit to check out next.

Git bisect solves this by treating commit history as a sorted array. It assumes there is a contiguous block of good commits, followed by a contiguous block of bad commits, and it finds the boundary using binary search. The only requirement is that you can identify one good commit and one bad commit. Everything in between is bisected automatically.

Manual bisect: the five-command workflow

Start by finding a known-good commit. Often this is the tag from the previous release. Then find a known-bad commit, usually the tip of main after the broken deploy.

# Start the session
git bisect start

# Mark the current HEAD as broken
git bisect bad

# Mark the last known good release
git bisect good v1.42.0

Git checks out a commit roughly halfway between the two. You build, run your reproduction, and tell Git the result.

# If the bug is present at this commit
git bisect bad

# If the bug is NOT present
git bisect good

Git picks the next midpoint. Repeat. Eight iterations later, Git prints the first bad commit hash, author, date, and message. Run git bisect reset to return to your original branch.

This alone saves hours, but it still requires you to sit at the keyboard and babysit the build. The real power is automation.

Automating the hunt with git bisect run

git bisect run executes a script at each midpoint and uses the exit code to decide whether the commit is good, bad, or should be skipped. The contract is simple:

  • Exit 0: this commit is good (bug not present).
  • Exit 1 through 127: this commit is bad (bug present).
  • Exit 125: this commit should be skipped (build breaks, test is flaky, unrelated infrastructure is down).

The script must be deterministic. If it depends on a database that has since been migrated, an external API with rate limits, or a test that fails 10% of the time, bisect will either crash or produce garbage. The fix is to make the script self-contained.

Here is a template for a Node.js project that uses Docker to provide a predictable environment.

#!/usr/bin/env bash
set -euo pipefail

# Clean up any previous build artifacts
rm -rf node_modules dist

# Install dependencies using the lockfile from this commit
npm ci

# Build if needed
npm run build

# Start a throwaway Postgres container for integration tests
docker run -d --name bisect-pg-$BASHPID \
  -e POSTGRES_PASSWORD=bisect \
  -p 5433:5432 postgres:15-alpine > /dev/null

# Wait for Postgres to accept connections
sleep 2
until docker exec bisect-pg-$BASHPID pg_isready -U postgres > /dev/null 2>&1; do
  sleep 1
done

# Run migrations against the test port
DATABASE_URL=postgres://postgres:bisect@localhost:5433/postgres npm run db:migrate

# Run the specific reproduction test
# This test must return 0 when the bug is absent, non-zero when present
npm run test:reproduction || true
EXIT_CODE=$?

# Tear down the database
docker stop bisect-pg-$BASHPID > /dev/null
docker rm bisect-pg-$BASHPID > /dev/null

exit $EXIT_CODE

Save this as scripts/bisect.sh, make it executable, and run:

git bisect start
git bisect bad HEAD
git bisect good v1.42.0
git bisect run ./scripts/bisect.sh

Git will check out commits, run the script, parse the exit code, and print the bad commit. The $BASHPID trick ensures that if you run multiple bisects in parallel (for example, on different machines), their database containers do not collide.

What makes a good bisect script

The most common failure mode is not a broken script. It is a script that is too slow. If your full test suite takes fifteen minutes, and bisect needs eight iterations, that is two hours. The reproduction test should be as minimal as possible. It should compile only what is necessary, run only the one test that detects the bug, and avoid network calls to external services.

If the bug is an API returning the wrong status code, the script can be a ten-line curl command piped to jq.

#!/usr/bin/env bash
set -euo pipefail

npm ci
npm run build
npm start &
SERVER_PID=$!
sleep 3

# The bug: this endpoint should return 200, but after the bad commit it returns 500
STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/health)

kill $SERVER_PID
wait $SERVER_PID 2>/dev/null || true

if [ "$STATUS" -eq 200 ]; then
  exit 0  # good
else
  exit 1  # bad
fi

This script is fast because it skips the entire test suite and checks only the symptom. If the server fails to start at a particular commit (maybe a dependency was temporarily broken), the script will exit non-zero and bisect will mark that commit as bad even though it is not the regression. That is where exit 125 matters.

Skipping commits that cannot be tested

Sometimes the build is broken at a midpoint. A dependency update broke npm install, or a migration file was temporarily malformed, or the TypeScript config had a syntax error for one commit. If your script returns 1, bisect assumes the bug is present and keeps searching in the older half of the history. If the bug is actually newer, bisect will wander into the weeds and report the wrong commit.

Exit 125 tells bisect “I cannot determine good or bad at this commit, skip it.” Git will treat the skipped commit as untested and narrow around it.

# Inside bisect.sh
if ! npm run build > /dev/null 2>&1; then
  echo "Build failed at this commit, skipping"
  exit 125
fi

The risk is that if you skip too many commits, bisect may be unable to isolate a single bad commit. It will report a range instead. That range is still useful, it narrows the search from two hundred commits to maybe five, but it means your history has too much noise. Treat frequent skips as a signal that your main branch is not reliably buildable, which is a problem worth fixing on its own.

Bisecting through merge commits

On a team that uses merge commits, bisecting can feel non-linear because merge commits have two parents. By default, git bisect will sometimes step into a feature branch that was merged, testing commits that never landed on main individually. This is technically correct but often irrelevant. You usually care about which merged branch introduced the bug, not which specific commit inside that branch.

Add --first-parent to bisect only along the main line.

git bisect start --first-parent
git bisect bad HEAD
git bisect good v1.42.0
git bisect run ./scripts/bisect.sh

This treats merge commits as single units. If a merged branch is bad, bisect identifies the merge commit itself as the first bad commit. That is usually what you want for a postmortem. The follow-up investigation happens inside that branch, but the boundary on main is clear.

Bisecting performance regressions

Not every regression is a crash or a wrong status code. Sometimes the regression is latency. The API still returns 200, but the p95 doubled between releases. Bisect works here too, as long as your script can measure the performance and return an exit code based on a threshold.

#!/usr/bin/env bash
set -euo pipefail

npm ci
npm run build
npm start &
SERVER_PID=$!
sleep 3

# Warmup
curl -s http://localhost:3000/api/heavy-endpoint > /dev/null

# Measure
curl -s -w "%{time_total}" -o /dev/null http://localhost:3000/api/heavy-endpoint > /tmp/bisect-timing.txt
LATENCY=$(cat /tmp/bisect-timing.txt)

kill $SERVER_PID
wait $SERVER_PID 2>/dev/null || true

# Threshold in seconds
if (( $(echo "$LATENCY < 0.5" | bc -l) )); then
  exit 0  # good
else
  exit 1  # bad
fi

Performance bisecting is more fragile than functional bisecting. Machine load, Docker networking, and background processes can add noise. Run the measurement three times and take the median if your latency budget is tight. If the noise is too high, return 125 and let bisect narrow around the uncertain commits.

Integrating bisect into CI

The highest-leverage use of bisect is not firefighting. It is prevention. When a test fails on main after a merge, most teams look at the merged PR and assume the PR is at fault. But if main was already broken by an earlier commit that did not trigger the test (maybe because the test was added later), blaming the most recent PR sends the wrong engineer on a wild goose chase.

A CI pipeline can automate bisect to find the true first bad commit. On main branch failure, the pipeline checks out the code, finds the last known green commit (from the previous successful CI run), and runs git bisect run with the failing test as the script. It posts the bad commit SHA to Slack or creates a ticket.

Here is a GitHub Actions job that does this.

  bisect-regression:
    runs-on: ubuntu-latest
    if: failure()
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Find last green commit
        id: last-green
        run: |
          # In practice, query your CI API or check git tags
          LAST_GREEN=$(git rev-list -n 1 --before="2 hours ago" origin/main)
          echo "commit=$LAST_GREEN" >> "$GITHUB_OUTPUT"

      - name: Run bisect
        run: |
          git bisect start
          git bisect bad HEAD
          git bisect good ${{ steps.last-green.outputs.commit }}
          git bisect run npm run test:ci -- --grep "regression-suite"

The --grep flag limits the test to the specific suite that failed, keeping bisect fast. You will want to cache node_modules between iterations if your test suite is heavy, but be careful: caching across commits can hide dependency changes. A clean install per iteration is slower but safer.

The edge cases that waste your time

Submodules. If your repo uses Git submodules, bisect will not automatically update them to the correct commit for the checked-out midpoint. Your script must run git submodule update --init --recursive before building, or you will test the wrong code.

Generated files. If your build pipeline generates files that are not in .gitignore, bisect may report a dirty working tree and refuse to switch commits. Run git clean -fdx at the start of every bisect script to ensure a pristine state.

Environment variables. If your reproduction depends on an environment variable that changes between commits (for example, a feature flag that was toggled manually during the bisected period), the script must set that variable explicitly. Bisect assumes the only variable is the code itself.

Non-deterministic tests. A flaky test that fails 5% of the time will eventually return 1 on a good commit and send bisect down the wrong path. If you know a test is flaky, run it multiple times inside the script and return 125 unless all runs agree.

FAILS=0
for i in {1..3}; do
  npm run test:reproduction || FAILS=$((FAILS + 1))
done

if [ "$FAILS" -eq 0 ]; then
  exit 0
elif [ "$FAILS" -eq 3 ]; then
  exit 1
else
  exit 125
fi

The takeaway

Finding a regression by hand is linear, error-prone, and demoralizing. Git bisect is logarithmic, mechanical, and automatable. The investment is one reproduction test script. The return is a ten-minute automated search that finds the exact commit, even across merge commits, even in a noisy history.

Write the script before you need it. Keep it fast, self-contained, and deterministic. Add --first-parent if your team uses merge commits. Return 125 when the build breaks. And integrate it into CI so the next time main goes red, the pipeline tells you which commit broke it before the standup starts.

The next time production breaks after a multi-day sprint, you will not be hand-checkout-testing two hundred commits. You will be running one command and reading the bad commit hash while your coffee brews.


A note from Yojji

The teams that ship reliably are not the ones that never break production. They are the ones that can pinpoint the breaking change, revert or patch it precisely, and prevent the same class of failure from recurring. Automated bisect workflows, deterministic reproduction scripts, and CI integrations that catch regressions at the commit boundary are standard practice in the backend engineering culture Yojji builds with its partners.

Yojji is an international custom software development company founded in 2016, with teams across Europe, the US, and the UK. They specialize in the JavaScript ecosystem (React, Node.js, TypeScript), cloud platforms (AWS, Azure, Google Cloud), and the kind of disciplined debugging workflows that turn production fires into routine maintenance.