Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/bun-usockets/src/internal/fault_inject.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ enum us_fault_syscall {
* always fresh from the kernel here, so the failure path is unreachable
* without fault injection. Only US_FAULT_ERRNO applies. */
US_FAULT_POLL_START,
/* Not a syscall: the JS Buffer allocated for a TLS session/keylog payload
* in the Rust on_session/on_keylog dispatch. It only fails on JSC heap
* OOM, so the failure path is unreachable without injection. Only
* US_FAULT_ERRNO applies, and the errno value is ignored — the simulated
* failure is a thrown JS out-of-memory error, not an errno. */
US_FAULT_SESSION_BUFFER,
US_FAULT_COUNT
};

Expand Down
9 changes: 5 additions & 4 deletions src/js/internal-for-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ export const setSocketOptions: setSocketOptionsFn = $newRustFunction(
/**
* The syscalls instrumented in bsd.c, plus non-syscall hooks whose failure
* paths are otherwise unreachable without injection ("ssl_loop_buffer",
* "poll_start"; see fault_inject.h for the per-hook description). Arming
* anything else is rejected.
* "poll_start", "session_buffer"; see fault_inject.h for the per-hook
* description). Arming anything else is rejected.
*/
export type SocketFaultSyscall =
| "recv"
Expand All @@ -339,7 +339,8 @@ export type SocketFaultSyscall =
| "connect"
| "accept"
| "ssl_loop_buffer"
| "poll_start";
| "poll_start"
| "session_buffer";

export type SocketFaultRule = {
syscall: SocketFaultSyscall;
Expand All @@ -366,7 +367,7 @@ export type SocketFaultRule = {
after?: number;
/** fire this many times then disarm; -1 = forever. Default 1. */
repeat?: number;
/** match only this fd; -1 (default) = any. Rejected for "ssl_loop_buffer", which has no fd. */
/** match only this fd; -1 (default) = any. Rejected for "ssl_loop_buffer" and "session_buffer", which have no fd. */
fd?: number;
};

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/socket/Listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ fn connect_finish<const IS_SSL: bool>(
};
{
let this = socket;
let _ = NewSocket::<IS_SSL>::handle_connect_error(this, errno, 0);
NewSocket::<IS_SSL>::handle_connect_error(this, errno, 0);
// Balance the unconditional `socket_ref.ref_()` above.
NewSocket::deref(&this);
}
Expand Down
20 changes: 12 additions & 8 deletions src/runtime/socket/WindowsNamedPipeContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,21 @@ impl WindowsNamedPipeContext {
// Only the TLS wrapper parks sessions; the TCP arm can never get here.
// SAFETY: see `on_open`.
if let SocketType::Tls(s) = unsafe { (*this).socket } {
let _ = TLSSocket::on_session(s, session);
TLSSocket::on_session(s, session);
}
}

fn on_keylog(this: *mut Self, line: &[u8]) {
// SAFETY: see `on_open`.
if let SocketType::Tls(s) = unsafe { (*this).socket } {
let _ = TLSSocket::on_keylog(s, line);
TLSSocket::on_keylog(s, line);
}
}

fn on_handshake(this: *mut Self, success: bool, ssl_error: us_bun_verify_error_t) {
// SAFETY: see `on_open`.
let (socket, pipe) = unsafe { ((*this).socket, ptr::addr_of_mut!((*this).named_pipe)) };
match_socket!(socket, |s: NewSocket<SSL>| _ = NewSocket::on_handshake(
match_socket!(socket, |s: NewSocket<SSL>| NewSocket::on_handshake(
s,
socket_from_named_pipe::<SSL>(pipe),
success as i32,
Expand Down Expand Up @@ -243,8 +243,11 @@ impl WindowsNamedPipeContext {
s.handle_error(js_err);
});
} else {
match_socket!(socket, |s: NewSocket<SSL>| _ =
NewSocket::handle_connect_error(s, err.errno as i32, 0));
match_socket!(socket, |s: NewSocket<SSL>| NewSocket::handle_connect_error(
s,
err.errno as i32,
0
));
}
}

Expand All @@ -266,7 +269,7 @@ impl WindowsNamedPipeContext {
(socket, ptr::addr_of_mut!((*this).named_pipe))
};
match_socket!(socket, |s: NewSocket<SSL>| {
_ = NewSocket::on_close(s, socket_from_named_pipe::<SSL>(pipe), 0, None);
NewSocket::on_close(s, socket_from_named_pipe::<SSL>(pipe), 0, None);
// Release the +1 ref taken in `create()`.
s.get().deref();
});
Expand Down Expand Up @@ -302,8 +305,9 @@ impl WindowsNamedPipeContext {
fn fail_and_release(this: *mut Self) {
// SAFETY: `this` is live; `create()` returned it and no deref has fired yet.
// +1 ref held on the inner socket; live until `Self::deref` below.
match_socket!(unsafe { (*this).socket }, |s: NewSocket<SSL>| _ =
NewSocket::handle_connect_error(s, SystemErrno::ENOENT as i32, 0));
match_socket!(unsafe { (*this).socket }, |s: NewSocket<SSL>| {
NewSocket::handle_connect_error(s, SystemErrno::ENOENT as i32, 0)
});
// SAFETY: `this` was just returned from `create()` (refcount==1);
// release the only ref on the errdefer path.
unsafe { Self::deref(this) };
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<const SSL: bool> uws_handlers::RawSocketEvents<SSL> for NewSocket<SSL> {
code: i32,
reason: *mut core::ffi::c_void,
) {
let _ = NewSocket::on_close(
NewSocket::on_close(
this,
s,
code,
Expand All @@ -167,7 +167,7 @@ impl<const SSL: bool> uws_handlers::RawSocketEvents<SSL> for NewSocket<SSL> {
s: bun_uws::NewSocketHandler<SSL>,
code: i32,
) {
let _ = NewSocket::on_connect_error(this, s, code);
NewSocket::on_connect_error(this, s, code);
}
#[inline]
fn on_handshake(
Expand All @@ -176,6 +176,6 @@ impl<const SSL: bool> uws_handlers::RawSocketEvents<SSL> for NewSocket<SSL> {
ok: i32,
err: bun_uws_sys::us_bun_verify_error_t,
) {
let _ = NewSocket::on_handshake(this, s, ok, err);
NewSocket::on_handshake(this, s, ok, err);
}
}
Loading