Skip to content

Remove dead code from bun_http_jsc, the node:http fallback handle, and the c-ares config - #45753

Open
robobun wants to merge 1 commit into
mainfrom
robobun/b7cafab0/dead-code-sweep
Open

robobun wants to merge 1 commit into
mainfrom
robobun/b7cafab0/dead-code-sweep

Conversation

@robobun

@robobun robobun commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Behaviour change: none

Problem

Fix

Background

  • The fallback handle is a JS object that stands in for the native NodeHTTPResponse when node:http serves a socket that Bun's HTTP server does not own.
  • scripts/build/deps/cares.ts writes the ares_config.h of c-ares from per-platform lists of macro names. A name that no source file tests has no effect.
  • Considered the full sweep of 12 files (139 deleted lines). Open PRs delete, rewrite or call 133 of those lines, so only the other 6 stay. Notes list the rest.

Downsides

  • The fallback handle has one own property less, visible only to code that inspects that internal object.
  • None found for the dependency and the macros.
Notes

Tests that use the fallback handle, run with the debug build: test/js/node/test/parallel/test-http-generic-streams.js, test-http2-allow-http1.js, test-http2-https-fallback.js, test-http2-https-fallback-http-server-options.js.

What this run scanned:

  • Rust: relinked the debug objects of main with --gc-sections and joined the symbol tables with DWARF declaration lines. 1068 source functions lose every instance. Each candidate was deleted and cargo check --workspace ran for Windows, macOS, FreeBSD and Linux with --all-targets. A compile error put the candidate back. Most candidates are Windows or macOS code, const fn builders, or debugger helpers.
  • The same loop ran over 631 pub generic or #[inline] functions that the debug binary never instantiates.
  • No .rs file is outside every crate's dep-info. The linker drops no non-inline function from a .cpp file under src/.
  • src/js, scripts/, misctools/, and the small packages: read for unused bindings, members and files.

Found, and left to the pull request that owns the lines:

Probably dead, not in this diff:

  • AbortSignal__Timeout__run (src/jsc/AbortSignal.rs): a #[no_mangle] export that no C++ file names.
  • 38 manual Debug impls that nothing formats, 27 of them in src/lint.
  • The shim that #[host_fn] generates for a method of a .classes.ts class: the linker drops it for BuildMessage, ResolveMessage and Subprocess.
  • misctools/generate-cli-completions.ts and completions/bun-cli.json: nothing in the repository reads the JSON.

…d the c-ares config

- bun_http_jsc: the bstr dependency. The WebSocket rewrite removed the
  last use.
- http1_server_fallback.ts: the shouldKeepAlive member of the fallback
  response handle. ServerResponse keeps its own flag, so nothing reads
  the member. The closure parameter of the same name stays in use.
- scripts/build/deps/cares.ts: HAVE_SYS_SOCKIO_H, HAVE_WS2IPDEF_H and
  HAVE_IO_H. No c-ares source file reads them.
@robobun

robobun commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 12:57 PM PT - Oct 17th, 2026

✅ @robobun, your commit e47f71c3913586500a9c0f9302e87d995fea2246 passed in Build #127596! 🎉


🧪   To try this PR locally:

bunx bun-pr 45753

That installs a local version of the PR into your bun-45753 executable, so you can run:

bun-45753 --bun

@robobun

robobun commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: ready for review. CI is green.

How this was verified:

  • rg finds no reader for any removed name. The PR body lists the searches.
  • CI compiled c-ares with the new config on every build lane: Linux, macOS, Windows and FreeBSD. All test lanes passed.
  • bun bd passes. cargo check -p bun_http_jsc --all-targets passes for Linux, Windows, macOS and FreeBSD.
  • These tests use the fallback handle and pass with the debug build: test-http-generic-streams.js, test-http2-allow-http1.js, test-http2-https-fallback.js, test-http2-https-fallback-http-server-options.js.

PR: #45753

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: oven-sh/bun/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 060af973-cf36-4cd5-810a-4dde60609db0
📥 Commits

Reviewing files that changed from the base of the PR and between 017b243 and e47f71c.

⛔ Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing: 3
  • scripts/build/deps/cares.ts
  • src/http_jsc/Cargo.toml
  • src/js/internal/http1_server_fallback.ts
💤 Files with no reviewable changes: 2
  • src/js/internal/http1_server_fallback.ts
  • src/http_jsc/Cargo.toml

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

The changes remove selected platform header macros, the bstr workspace dependency from bun_http_jsc, and the shouldKeepAlive property from the internal HTTP/1 fallback response handle.

Changes

Platform feature macros

Layer / File(s) Summary
Header macro updates
scripts/build/deps/cares.ts
Darwin and FreeBSD no longer define HAVE_SYS_SOCKIO_H. Windows no longer defines HAVE_WS2IPDEF_H or HAVE_IO_H.

HTTP JSC dependency

Layer / File(s) Summary
Remove bstr dependency
src/http_jsc/Cargo.toml
Removes the bstr.workspace = true dependency declaration.

HTTP fallback response handle

Layer / File(s) Summary
Update response handle
src/js/internal/http1_server_fallback.ts
Removes the shouldKeepAlive property from the internal response handle.

Suggested reviewers: cirospaciari

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to e47f7

The removals have no established behavior regression and are ready to merge after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly summarizes the three main dead-code removals: the bun_http_jsc dependency, the node:http fallback handle member, and the c-ares configuration macros.
Description check Passed The description explains the problem, fix, behavior impact, verification steps, and background. It does not use the exact template headings, but it provides the required information and is mostly comp…
Full details: Description check

Explanation

The description explains the problem, fix, behavior impact, verification steps, and background. It does not use the exact template headings, but it provides the required information and is mostly complete.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this PR and didn't find any bugs. Two of the three removals check out fully from this checkout; the c-ares macro removal affects the generated ares_config.h on Darwin, FreeBSD and Windows and can only be confirmed against the vendored c-ares tree (not present here), so a quick human check of those platforms' builds is still worthwhile.

What was reviewed:

  • bstr drop in src/http_jsc/Cargo.toml and Cargo.lock: no remaining bstr reference anywhere under src/http_jsc, including cfg-gated code.
  • shouldKeepAlive removal from the fallback handle: the parameter is still used for the socket keep-alive decision at line 137; every .shouldKeepAlive reader in src/js/node and test/ is on req/res, and ServerResponse.prototype.shouldKeepAlive is backed by its own kShouldKeepAlive slot, never the handle.
  • HAVE_SYS_SOCKIO_H, HAVE_WS2IPDEF_H, HAVE_IO_H in scripts/build/deps/cares.ts: no other consumer in the repo; whether c-ares sources at the pinned commit still test them cannot be checked from this clone.
Extended reasoning...

The change is a 3-insertion / 6-deletion dead-code sweep across four files: an unused Rust dependency in bun_http_jsc with its lockfile entry, an unread property on the JS node:http fallback response handle, and three HAVE_* feature macros in the hand-maintained c-ares config tables. It touches no security-sensitive surface. The Rust and JS removals were verified in-repo by grep (no bstr use; no handle.shouldKeepAlive reader). The c-ares macros change platform-gated generated config for Darwin, FreeBSD and Windows, and the vendored c-ares tree is not checked out here, so the author's claim that no source file reads them could not be independently confirmed; the failure mode would most likely be a loud compile error on those CI lanes rather than silent misbehavior, but that is what tipped the decision to defer rather than approve.

@robobun

robobun commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator Author

On the c-ares macros, the one point the review could not check:

  • The pinned c-ares tree has no reader for the three names. rg -lw over vendor/cares finds HAVE_SYS_SOCKIO_H only in CMakeLists.txt and Makefile.netware, HAVE_WS2IPDEF_H only in configure.ac, and HAVE_IO_H in no file.
  • The build-bun lanes for macOS, Windows and FreeBSD (x64 and aarch64) compiled c-ares with the new config and passed.

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants