Skip to content

require('http') links runtime-only, so stdlib builtins return undefined (ESM import works) #8547

Description

@proggeramlug

crates/perry/tests/issue_4903_listen_callback_deferred.rs fails both its tests on main, and it is now the only thing keeping the sweep-tier cargo-test red (and therefore main-gate).

thread 'late_listening_listener_fires' panicked at issue_4903_listen_callback_deferred.rs:45
thread 'listen_callback_is_deferred_and_this_bound' panicked at issue_4903_listen_callback_deferred.rs:45
test result: FAILED. 0 passed; 2 failed

Line 45 is the "compiled binary failed" assertion, so this is a runtime failure, not a wrong value.

Reduced. http.createServer returns undefined in every form, while the export itself is a function:

const http = require('http');
console.log('no-arg      :', typeof http.createServer());                       // undefined
console.log('with-handler:', typeof http.createServer(function () {}));         // undefined
console.log('arrow       :', typeof http.createServer(() => {}));               // undefined
console.log('createServer:', typeof http.createServer);                         // function

Node prints object for the first three. The test's own failure is downstream of this — .listen(0, cb) on undefined throws TypeError: Cannot read properties of undefined (reading 'listen').

Where it comes from. ("http", "createServer") in native_module_dispatch/dispatch_d_i.rs routes through JS_NATIVE_HTTP_DISPATCH, and returns undefined when that pointer is null:

let ptr = crate::value::JS_NATIVE_HTTP_DISPATCH.load(Ordering::SeqCst);
if ptr.is_null() { f64::from_bits(JSValue::undefined().bits()) } else {}

That pointer is only installed by perry-stdlib's common/dispatch/init.rs:689, under #[cfg(feature = "external-http-server-pump")] — and that feature is not part of perry-stdlib's default/full set. So the question is whether the compile path that these tests exercise links a stdlib with the feature on. Locally the compile reports Linking (runtime-only), which is consistent with an http-using program being linked without the http implementation.

Two things I ruled out while narrowing, worth stating so the next person does not repeat them:

Repro: RUST_TEST_THREADS=1 cargo test --release -p perry --test issue_4903_listen_callback_deferred, or compile the four-line snippet above and run it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions