Skip to content

base: add Exit function to replace direct os.Exit calls#5865

Draft
williamchoe3 wants to merge 1 commit intocockroachdb:masterfrom
williamchoe3:pebble-exit-func
Draft

base: add Exit function to replace direct os.Exit calls#5865
williamchoe3 wants to merge 1 commit intocockroachdb:masterfrom
williamchoe3:pebble-exit-func

Conversation

@williamchoe3
Copy link
Copy Markdown

Summary

Add a package-level Exit function in internal/base that wraps os.Exit. Embedders (e.g. CockroachDB) can override base.Exit to route invariant violation exits through their own fatal logging infrastructure.

Previously, 20 call sites in production code called os.Exit(1) directly, which bypassed any logging or crash reporting the embedder had set up. The process would simply vanish with exit code 1 and no indication of why.

All os.Exit calls in production code (cache invariant checks, memtable assertions, sstable reader checks, the unreferenced DB finalizer, and the default logger) are replaced with base.Exit. CLI tools, test utilities, and metamorphic testing code are left unchanged.

Informs #2061

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Add a package-level Exit function in internal/base that wraps os.Exit.
Embedders (e.g. CockroachDB) can override base.Exit to route invariant
violation exits through their own fatal logging infrastructure, giving
them visibility into why the process died (log lines, crash reports,
marker files).

Previously, 20 call sites in production code called os.Exit(1) directly,
which bypassed any logging or crash reporting the embedder had set up.
The process would simply vanish with exit code 1 and no indication of
why.

Informs cockroachdb#2061
williamchoe3 added a commit to williamchoe3/cockroach that referenced this pull request Mar 26, 2026
Set pebble.Options.ExitFunc so that Pebble invariant violation exits
(cache assertions, memtable checks, sstable reader checks) route
through CockroachDB's log.Fatal path instead of calling os.Exit(1)
directly. This gives visibility into why the process died via log
lines, Sentry crash reports, and fatal exit marker files.

Requires cockroachdb/pebble#5865.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@github-actions
Copy link
Copy Markdown

Potential Bug(s) Detected

The three-stage Claude Code analysis has identified potential bug(s) in this PR that may warrant investigation.

Next Steps:
Please review the detailed findings in the workflow run.

Note: When viewing the workflow output, scroll to the bottom to find the Final Analysis Summary.

After you review the findings, please tag the issue as follows:

  • If the detected issue is real or was helpful in any way, please tag the issue with O-AI-Review-Real-Issue-Found
  • If the detected issue was not helpful in any way, please tag the issue with O-AI-Review-Not-Helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants