diff --git a/Cargo.lock b/Cargo.lock index d5cf3a1e8e62..562844f3a75a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -282,7 +282,6 @@ dependencies = [ "bun_wyhash", "bun_zstd", "bytemuck", - "const_format", "enum-map", "lol_html", "scopeguard", @@ -324,7 +323,6 @@ dependencies = [ "bun_resolver", "bun_standalone_graph", "bun_sys", - "enum-map", "scopeguard", "thiserror", ] @@ -376,8 +374,6 @@ dependencies = [ "paste", "rustc-hash", "smallvec", - "strum", - "thiserror", ] [[package]] @@ -434,7 +430,6 @@ dependencies = [ "bun_zlib", "const_format", "libc", - "scopeguard", "thiserror", ] @@ -465,14 +460,9 @@ dependencies = [ "bun_paths", "bun_ptr", "bun_wyhash", - "const_format", - "enum-map", - "enumset", - "libc", "scopeguard", "strum", "thiserror", - "typed-arena", ] [[package]] @@ -634,7 +624,6 @@ dependencies = [ "bun_wyhash", "bun_zlib", "bun_zstd", - "scopeguard", "strum", "thiserror", ] @@ -694,7 +683,6 @@ dependencies = [ "bun_core", "bun_dotenv", "bun_install_types", - "bun_js_parser", "bun_parsers", "bun_url", "strum", @@ -745,7 +733,6 @@ dependencies = [ "bun_threading", "bun_transpiler", "bun_url", - "bun_uws", "bun_which", "bun_wyhash", "bytemuck", @@ -799,15 +786,11 @@ dependencies = [ "bun_core", "bun_dispatch", "bun_errno", - "bun_opaque", - "bun_paths", "bun_ptr", "bun_spawn_sys", "bun_sys", "bun_threading", "bun_uws_sys", - "const_format", - "enum-map", "enumset", "libc", "scopeguard", @@ -881,10 +864,8 @@ dependencies = [ "bun_sourcemap", "bun_wyhash", "bytemuck", - "const_format", "enum-map", "enumset", - "scopeguard", "thiserror", ] @@ -927,7 +908,6 @@ dependencies = [ "bun_spawn", "bun_sys", "bun_threading", - "bun_transpiler", "bun_url", "bun_uws", "bun_watcher", @@ -980,7 +960,6 @@ dependencies = [ "bun_core", "bun_windows_sys", "bun_wyhash", - "libc", "strum", ] @@ -1140,7 +1119,6 @@ dependencies = [ name = "bun_platform" version = "0.0.0" dependencies = [ - "bun_core", "libc", ] @@ -1152,7 +1130,6 @@ dependencies = [ "bun_alloc", "bun_core", "bun_core_macros", - "scopeguard", ] [[package]] @@ -2882,12 +2859,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "typed-arena" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" - [[package]] name = "typenum" version = "1.20.0" diff --git a/Cargo.toml b/Cargo.toml index 8fecc8c9ac0d..2b3d68f97ea4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -362,7 +362,6 @@ rustix = { version = "0.38", default-features = false, features = ["std", "fs", bitflags = "2" thiserror = "2" smallvec = "1" -typed-arena = "2" itoa = "1" encoding_rs = "0.8.35" # Vendored, not crates.io — see the `exclude = ["vendor"]` note above. diff --git a/packages/bun-usockets/src/context.c b/packages/bun-usockets/src/context.c index 53adb19611bc..9542530f0903 100644 --- a/packages/bun-usockets/src/context.c +++ b/packages/bun-usockets/src/context.c @@ -167,10 +167,6 @@ void us_socket_group_close_all(struct us_socket_group_t *group) { us_socket_group_close_all_ex(group, 1); } -unsigned short us_socket_group_timestamp(struct us_socket_group_t *group) { - return group->timestamp; -} - __attribute__((always_inline)) struct us_loop_t *us_socket_group_loop(struct us_socket_group_t *group) { return group->loop; } @@ -179,10 +175,6 @@ __attribute__((always_inline)) void *us_socket_group_ext(struct us_socket_group_ return group->ext; } -struct us_socket_group_t *us_socket_group_next(struct us_socket_group_t *group) { - return group->next; -} - /* ── Link / unlink ──────────────────────────────────────────────────────── */ static inline int us_internal_group_is_empty(struct us_socket_group_t *group) { @@ -502,10 +494,6 @@ void us_listen_socket_close(struct us_listen_socket_t *ls) { /* We cannot immediately free a listen socket as we can be inside an accept loop */ } -__attribute__((always_inline)) void *us_listen_socket_ext(struct us_listen_socket_t *ls) { - return ls + 1; -} - struct us_listen_socket_t *us_socket_group_head_listen_socket(struct us_socket_group_t *group) { return group->head_listen_sockets; } @@ -518,10 +506,6 @@ LIBUS_SOCKET_DESCRIPTOR us_listen_socket_get_fd(struct us_listen_socket_t *ls) { return us_poll_fd(&ls->s.p); } -int us_listen_socket_port(struct us_listen_socket_t *ls) { - return us_socket_local_port(&ls->s); -} - struct us_socket_group_t *us_listen_socket_group(struct us_listen_socket_t *ls) { return ls->accept_group; } diff --git a/packages/bun-usockets/src/crypto/openssl.c b/packages/bun-usockets/src/crypto/openssl.c index ade2a551c741..33b473a212f1 100644 --- a/packages/bun-usockets/src/crypto/openssl.c +++ b/packages/bun-usockets/src/crypto/openssl.c @@ -3064,27 +3064,6 @@ void us_listen_socket_remove_server_name(struct us_listen_socket_t *ls, sni_node_destructor(node); } -void *us_listen_socket_find_server_name_userdata(struct us_listen_socket_t *ls, - const char *hostname_pattern) { - if (!ls->sni) return NULL; - struct sni_node_t *node = (struct sni_node_t *)sni_find(ls->sni, hostname_pattern); - return node ? node->user : NULL; -} - -/* Returns the SSL_CTX registered for `hostname_pattern` via - * us_listen_socket_add_server_name, or NULL. Owned - the caller must release - * the reference. The on_server_name resolvers return owned references (the - * SNI dispatcher frees them after SSL_set_SSL_CTX takes its own), so the - * tree's reference must not be handed out as a borrow. */ -struct ssl_ctx_st *us_listen_socket_find_server_name_ctx(struct us_listen_socket_t *ls, - const char *hostname_pattern) { - if (!ls->sni) return NULL; - struct sni_node_t *node = (struct sni_node_t *)sni_find(ls->sni, hostname_pattern); - if (!node || !node->ctx) return NULL; - SSL_CTX_up_ref(node->ctx); - return node->ctx; -} - void us_listen_socket_on_server_name(struct us_listen_socket_t *ls, struct ssl_ctx_st *(*cb)(struct us_listen_socket_t *, const char *, int *, struct us_socket_t *)) { ls->on_server_name = cb; diff --git a/packages/bun-usockets/src/crypto/sni_tree.cpp b/packages/bun-usockets/src/crypto/sni_tree.cpp index fc0726acfeb6..e97dd2a7f476 100644 --- a/packages/bun-usockets/src/crypto/sni_tree.cpp +++ b/packages/bun-usockets/src/crypto/sni_tree.cpp @@ -31,9 +31,6 @@ #include #include -/* We only handle a maximum of 10 labels per hostname */ -#define MAX_LABELS 10 - /* This cannot be shared */ thread_local void (*sni_free_cb)(void *); diff --git a/packages/bun-usockets/src/fault_inject.c b/packages/bun-usockets/src/fault_inject.c index 4361c47ce2fa..38317fe10320 100644 --- a/packages/bun-usockets/src/fault_inject.c +++ b/packages/bun-usockets/src/fault_inject.c @@ -49,16 +49,6 @@ void us_fault_set(int sc, const struct us_fault_rule *rule) { Bun__unlock(&us_fault_lock); } -void us_fault_clear(int sc) { - if ((unsigned)sc >= US_FAULT_COUNT) return; - Bun__lock(&us_fault_lock); - us_fault_state[sc].rule.action = US_FAULT_NONE; - us_fault_state[sc].calls_seen = 0; - us_fault_state[sc].fired = 0; - us_fault_recompute_armed(); - Bun__unlock(&us_fault_lock); -} - void us_fault_clear_all(void) { Bun__lock(&us_fault_lock); for (int i = 0; i < US_FAULT_COUNT; i++) { diff --git a/packages/bun-usockets/src/internal/fault_inject.h b/packages/bun-usockets/src/internal/fault_inject.h index 4b4496bca19d..ad2b942fefbc 100644 --- a/packages/bun-usockets/src/internal/fault_inject.h +++ b/packages/bun-usockets/src/internal/fault_inject.h @@ -88,7 +88,6 @@ extern "C" { extern int us_fault_armed; void us_fault_set(int syscall, const struct us_fault_rule *rule); -void us_fault_clear(int syscall); void us_fault_clear_all(void); int us_fault_hit(int syscall, int fd, ssize_t *out, int *clamp); diff --git a/packages/bun-usockets/src/internal/internal.h b/packages/bun-usockets/src/internal/internal.h index c6310c201437..e1b3ad0735ca 100644 --- a/packages/bun-usockets/src/internal/internal.h +++ b/packages/bun-usockets/src/internal/internal.h @@ -105,10 +105,8 @@ enum { POLL_TYPE_POLLING_IN = 16, }; -#define POLL_TYPE_BITSIZE 5 // make sure to update epoll_kqueue.h if you change this #define POLL_TYPE_KIND_MASK 0b111 #define POLL_TYPE_POLLING_MASK 0b11000 -#define POLL_TYPE_MASK (POLL_TYPE_KIND_MASK | POLL_TYPE_POLLING_MASK) /* Bun APIs implemented in Zig */ void Bun__lock(zig_mutex_t *lock); diff --git a/packages/bun-usockets/src/internal/networking/bsd.h b/packages/bun-usockets/src/internal/networking/bsd.h index 4d53a9fa3fa6..5d9a7d3667f6 100644 --- a/packages/bun-usockets/src/internal/networking/bsd.h +++ b/packages/bun-usockets/src/internal/networking/bsd.h @@ -33,7 +33,6 @@ #include #include #pragma comment(lib, "ws2_32.lib") -#define SETSOCKOPT_PTR_TYPE const char * #define LIBUS_SOCKET_ERROR INVALID_SOCKET #else /* POSIX */ #ifndef _GNU_SOURCE @@ -42,7 +41,6 @@ /* For socklen_t */ #include #include -#define SETSOCKOPT_PTR_TYPE int * #define LIBUS_SOCKET_ERROR -1 #endif diff --git a/packages/bun-usockets/src/libusockets.h b/packages/bun-usockets/src/libusockets.h index d843768736bb..1529713afbf4 100644 --- a/packages/bun-usockets/src/libusockets.h +++ b/packages/bun-usockets/src/libusockets.h @@ -102,7 +102,6 @@ #define LIBUS_RECV_BUFFER_PADDING 32 /* Guaranteed alignment of extension memory */ #define LIBUS_EXT_ALIGNMENT 16 -#define ALLOW_SERVER_RENEGOTIATION 0 /* close() codes — two orthogonal bits collapsed into three states: * 0 graceful: TLS sends close_notify and DEFERS the fd close until the @@ -211,16 +210,8 @@ char *us_udp_packet_buffer_peer(struct us_udp_packet_buffer_t *buf, int index); /* Peeks ECN of received packet */ // int us_udp_packet_buffer_ecn(struct us_udp_packet_buffer_t *buf, int index); -/* Receives a set of packets into specified packet buffer */ -int us_udp_socket_receive(struct us_udp_socket_t *s, struct us_udp_packet_buffer_t *buf); - -void us_udp_buffer_set_packet_payload(struct us_udp_packet_buffer_t *send_buf, int index, int offset, void *payload, int length, void *peer_addr); - int us_udp_socket_send(struct us_udp_socket_t *s, void** payloads, size_t* lengths, void** addresses, int num); -/* Allocates a packet buffer that is reuable per thread. Mutated by us_udp_socket_receive. */ -struct us_udp_packet_buffer_t *us_create_udp_packet_buffer(); - /* Creates a (heavy-weight) UDP socket with a user space ring buffer. Again, this one is heavy weight and * shoud be reused. One entire QUIC server can be implemented using only one single UDP socket so weight * is not a concern as is the case for TCP sockets which are 1-to-1 with TCP connections. */ @@ -251,9 +242,6 @@ struct us_udp_socket_t *us_create_udp_socket_from_fd(us_loop_r loop, void (*data /* This one is ugly, should be ext! not user */ void *us_udp_socket_user(struct us_udp_socket_t *s); -/* Binds the UDP socket to an interface and port */ -int us_udp_socket_bind(struct us_udp_socket_t *s, const char *hostname, unsigned int port); - /* Public interfaces for timers. libuv (Windows) only — epoll/kqueue schedules * on bun.JSC.EventLoopTimer, no file descriptor or syscall. */ #ifdef _WIN32 @@ -361,10 +349,8 @@ void us_socket_group_close_all_ex(us_socket_group_r group, int also_listeners) n * (see close_all_ex). */ int us_loop_close_all_groups(us_loop_r loop) nonnull_fn_decl; -unsigned short us_socket_group_timestamp(us_socket_group_r group) nonnull_fn_decl; struct us_loop_t *us_socket_group_loop(us_socket_group_r group) nonnull_fn_decl __attribute((returns_nonnull)); void *us_socket_group_ext(us_socket_group_r group) nonnull_fn_decl; -struct us_socket_group_t *us_socket_group_next(us_socket_group_r group) nonnull_fn_decl; /* Move an open socket between groups / kinds, optionally resizing its ext. * Replaces us_socket_context_adopt_socket + us_create_child_socket_context. @@ -412,11 +398,6 @@ int us_listen_socket_add_server_name(struct us_listen_socket_t *ls, __attribute__((nonnull(1, 2, 3))); void us_listen_socket_remove_server_name(struct us_listen_socket_t *ls, const char *hostname_pattern) nonnull_fn_decl; -void *us_listen_socket_find_server_name_userdata(struct us_listen_socket_t *ls, - const char *hostname_pattern) nonnull_fn_decl; -/* Returns an owned reference; the caller must release it. */ -struct ssl_ctx_st *us_listen_socket_find_server_name_ctx(struct us_listen_socket_t *ls, - const char *hostname_pattern) nonnull_fn_decl; /* Parses a PKCS#12 blob into malloc'd PEM key/cert/ca strings (caller frees); * returns 0 with a static *err_reason tag on failure. */ int us_ssl_parse_pkcs12(const char *data, size_t len, const char *pass, @@ -698,12 +679,9 @@ int us_socket_remote_port(us_socket_r s) nonnull_fn_decl; void us_socket_remote_address(us_socket_r s, char *nonnull_arg buf, int *nonnull_arg length) nonnull_fn_decl; void us_socket_local_address(us_socket_r s, char *nonnull_arg buf, int *nonnull_arg length) nonnull_fn_decl; -struct us_socket_t *us_socket_detach(us_socket_r s) nonnull_fn_decl; int us_socket_ipc_write_fd(us_socket_r s, const char *data, int length, int fd) nonnull_fn_decl; void us_socket_sendfile_needs_more(us_socket_r s) nonnull_fn_decl; -void *us_listen_socket_ext(struct us_listen_socket_t *ls) nonnull_fn_decl; LIBUS_SOCKET_DESCRIPTOR us_listen_socket_get_fd(struct us_listen_socket_t *ls) nonnull_fn_decl; -int us_listen_socket_port(struct us_listen_socket_t *ls) nonnull_fn_decl; struct us_socket_group_t *us_listen_socket_group(struct us_listen_socket_t *ls) nonnull_fn_decl; /* Walk a group's live listeners. The list is the source of truth — anything * that caches us_listen_socket_t* across event-loop ticks (e.g. a std::vector diff --git a/packages/bun-usockets/src/loop.c b/packages/bun-usockets/src/loop.c index 8daebaddf243..265ded7acf24 100644 --- a/packages/bun-usockets/src/loop.c +++ b/packages/bun-usockets/src/loop.c @@ -425,12 +425,6 @@ void us_internal_loop_post(struct us_loop_t *loop) { loop->data.post_cb(loop); } -#ifdef WIN32 -#define us_ioctl ioctlsocket -#else -#define us_ioctl ioctl -#endif - void us_internal_dispatch_ready_poll(struct us_poll_t *p, int error, int eof, int events) { switch (us_internal_poll_type(p)) { case POLL_TYPE_CALLBACK: { @@ -1081,5 +1075,3 @@ void us_loop_integrate(struct us_loop_t *loop) { __attribute__((always_inline)) void *us_loop_ext(struct us_loop_t *loop) { return loop + 1; } - -#undef us_ioctl diff --git a/packages/bun-usockets/src/node_quic_shim.c b/packages/bun-usockets/src/node_quic_shim.c index 05de1583669a..62d202f3f18b 100644 --- a/packages/bun-usockets/src/node_quic_shim.c +++ b/packages/bun-usockets/src/node_quic_shim.c @@ -526,7 +526,6 @@ lsquic_engine_t *us_nq_engine_new(int is_server, int is_http, const struct sockaddr *us_nq_spec_dest(const struct lsquic_out_spec *s) { return s->dest_sa; } const struct sockaddr *us_nq_spec_local(const struct lsquic_out_spec *s) { return s->local_sa; } -void *us_nq_spec_peer_ctx(const struct lsquic_out_spec *s) { return s->peer_ctx; } const struct iovec *us_nq_spec_iov(const struct lsquic_out_spec *s, size_t *n) { *n = s->iovlen; return s->iov; diff --git a/packages/bun-usockets/src/quic.c b/packages/bun-usockets/src/quic.c index 62f14539cfec..c617ca23f948 100644 --- a/packages/bun-usockets/src/quic.c +++ b/packages/bun-usockets/src/quic.c @@ -80,7 +80,6 @@ struct us_quic_socket_context_s { * the peer until idle timeout). */ struct us_quic_socket_s *conns; - void (*on_open)(us_quic_socket_t *); void (*on_hsk_done)(us_quic_socket_t *, int); void (*on_goaway)(us_quic_socket_t *); void (*on_close)(us_quic_socket_t *); @@ -558,7 +557,6 @@ static lsquic_conn_ctx_t *us_quic_on_new_conn(void *if_ctx, lsquic_conn_t *conn) us_internal_enable_sweep_timer(ctx->loop); qs->next = ctx->conns; ctx->conns = qs; - if (ctx->on_open) ctx->on_open(qs); return (lsquic_conn_ctx_t *) qs; } @@ -961,7 +959,6 @@ int us_quic_listen_socket_local_address(us_quic_listen_socket_t *ls, char *buf, #define DEF_CB(name, sig) \ void us_quic_socket_context_##name(us_quic_socket_context_t *ctx, sig) { ctx->name = cb; } -DEF_CB(on_open, void (*cb)(us_quic_socket_t *)) DEF_CB(on_hsk_done, void (*cb)(us_quic_socket_t *, int)) DEF_CB(on_goaway, void (*cb)(us_quic_socket_t *)) DEF_CB(on_close, void (*cb)(us_quic_socket_t *)) @@ -1061,15 +1058,6 @@ void us_quic_stream_shutdown(us_quic_stream_t *s) { if (s->stream) lsquic_stream_shutdown(s->stream, 1); } -/* lsquic_stream_write buffers until a full packet or shutdown; force the - * partial buffer into a packet so the peer sees streamed bytes promptly. */ -void us_quic_stream_flush(us_quic_stream_t *s) { - if (s->stream) { - lsquic_stream_flush(s->stream); - s->ctx->pending_write_bytes++; - } -} - void us_quic_stream_shutdown_read(us_quic_stream_t *s) { if (s->stream) lsquic_stream_shutdown(s->stream, 0); } @@ -1092,10 +1080,6 @@ void us_quic_stream_reset(us_quic_stream_t *s) { if (s->stream) lsquic_stream_maybe_reset(s->stream, 0x10C, 1); } -int us_quic_stream_has_unacked(us_quic_stream_t *s) { - return s->stream ? lsquic_stream_has_unacked_data(s->stream) : 0; -} - void *us_quic_stream_ext(us_quic_stream_t *s) { return s + 1; } us_quic_socket_t *us_quic_stream_socket(us_quic_stream_t *s) { @@ -1115,7 +1099,6 @@ const struct us_quic_header_t *us_quic_stream_header(us_quic_stream_t *s, unsign } void *us_quic_socket_ext(us_quic_socket_t *s) { return s + 1; } -us_quic_socket_context_t *us_quic_socket_context(us_quic_socket_t *s) { return s->ctx; } void us_quic_socket_remote_address(us_quic_socket_t *s, char *buf, int *len, int *port, int *is_ipv6) { const struct sockaddr *local, *peer; @@ -1371,13 +1354,12 @@ struct us_quic_pending_connect_s { int port; int reject_unauthorized; struct addrinfo_request *ai_req; - void *user; }; int us_quic_socket_context_connect( us_quic_socket_context_t *ctx, const char *host, int port, const char *sni, int reject_unauthorized, us_quic_socket_t **out_qs, - struct us_quic_pending_connect_s **out_pending, void *user) + struct us_quic_pending_connect_s **out_pending) { *out_qs = NULL; *out_pending = NULL; @@ -1414,15 +1396,10 @@ int us_quic_socket_context_connect( pc->port = port; pc->reject_unauthorized = reject_unauthorized; pc->ai_req = ai_req; - pc->user = user; *out_pending = pc; return 0; } -void *us_quic_pending_connect_user(struct us_quic_pending_connect_s *pc) { - return pc->user; -} - struct addrinfo_request *us_quic_pending_connect_addrinfo( struct us_quic_pending_connect_s *pc) { return pc->ai_req; } diff --git a/packages/bun-usockets/src/quic.h b/packages/bun-usockets/src/quic.h index d64c230b6941..ad809f48e565 100644 --- a/packages/bun-usockets/src/quic.h +++ b/packages/bun-usockets/src/quic.h @@ -88,9 +88,8 @@ struct addrinfo_request; int us_quic_socket_context_connect( us_quic_socket_context_t *ctx, const char *host, int port, const char *sni, int reject_unauthorized, us_quic_socket_t **out_qs, - struct us_quic_pending_connect_s **out_pending, void *user); + struct us_quic_pending_connect_s **out_pending); -void *us_quic_pending_connect_user(struct us_quic_pending_connect_s *pc); struct addrinfo_request *us_quic_pending_connect_addrinfo( struct us_quic_pending_connect_s *pc); us_quic_socket_t *us_quic_pending_connect_resolved( @@ -105,8 +104,6 @@ unsigned us_quic_socket_streams_avail(us_quic_socket_t *s); int us_quic_socket_status(us_quic_socket_t *s, char *buf, unsigned int len); /* Connection-level callbacks */ -void us_quic_socket_context_on_open(us_quic_socket_context_t *ctx, - void (*on_open)(us_quic_socket_t *)); /* Fires once the TLS handshake completes (client only). ok=0 means the * handshake failed; on_close follows shortly. */ void us_quic_socket_context_on_hsk_done(us_quic_socket_context_t *ctx, @@ -140,11 +137,9 @@ int us_quic_stream_send_headers(us_quic_stream_t *s, * header block follows separately. */ int us_quic_stream_send_informational(us_quic_stream_t *s, const char *status3); void us_quic_stream_shutdown(us_quic_stream_t *s); -void us_quic_stream_flush(us_quic_stream_t *s); void us_quic_stream_shutdown_read(us_quic_stream_t *s); void us_quic_stream_close(us_quic_stream_t *s); void us_quic_stream_reset(us_quic_stream_t *s); -int us_quic_stream_has_unacked(us_quic_stream_t *s); void *us_quic_stream_ext(us_quic_stream_t *s); us_quic_socket_t *us_quic_stream_socket(us_quic_stream_t *s); @@ -163,7 +158,6 @@ const struct us_quic_header_t *us_quic_stream_header(us_quic_stream_t *s, unsign /* Connection accessors */ void *us_quic_socket_ext(us_quic_socket_t *s); -us_quic_socket_context_t *us_quic_socket_context(us_quic_socket_t *s); void us_quic_socket_remote_address(us_quic_socket_t *s, char *buf, int *len, int *port, int *is_ipv6); void us_quic_socket_close(us_quic_socket_t *s); diff --git a/packages/bun-usockets/src/socket.c b/packages/bun-usockets/src/socket.c index 20f351f74b6c..52de3c26cfc8 100644 --- a/packages/bun-usockets/src/socket.c +++ b/packages/bun-usockets/src/socket.c @@ -346,47 +346,6 @@ __attribute__((always_inline)) struct us_socket_t *us_socket_close(struct us_soc return us_internal_socket_close_raw(s, code, reason); } -// This function is the same as us_socket_close but: -// - does not emit on_close event -// - does not close -struct us_socket_t *us_socket_detach(struct us_socket_t *s) { - if (!us_socket_is_closed(s)) { - struct us_loop_t *loop = s->group->loop; - - if (s->flags.low_prio_state == 1) { - /* Unlink this socket from the low-priority queue */ - if (!s->prev) loop->data.low_prio_head = s->next; - else s->prev->next = s->next; - - if (s->next) s->next->prev = s->prev; - - s->prev = 0; - s->next = 0; - s->flags.low_prio_state = 0; - s->group->low_prio_count--; - /* Mirror the else branch: if this was the last thing keeping the - * group linked, drop it from the loop now rather than waiting for - * the next link/unlink to notice. */ - us_internal_group_maybe_unlink(s->group); - } else { - us_internal_socket_group_unlink_socket(s->group, s); - } - us_poll_stop((struct us_poll_t *) s, loop); - - us_internal_ssl_detach(s); - - /* Link this socket to the close-list and let it be deleted after this iteration */ - s->next = loop->data.closed_head; - loop->data.closed_head = s; - - /* Mark the socket as closed */ - s->flags.is_closed = 1; - - return s; - } - return s; -} - struct us_socket_t *us_socket_pair(struct us_socket_group_t *group, unsigned char kind, int socket_ext_size, LIBUS_SOCKET_DESCRIPTOR *fds) { #if defined(LIBUS_USE_LIBUV) || defined(WIN32) return 0; diff --git a/packages/bun-uws/src/App.h b/packages/bun-uws/src/App.h index f2444a46bbde..008cb019fb08 100644 --- a/packages/bun-uws/src/App.h +++ b/packages/bun-uws/src/App.h @@ -181,41 +181,6 @@ struct TemplatedApp { return std::move(*this); } - TemplatedApp &&removeServerName(const std::string &hostname_pattern) { - if constexpr (SSL) { - /* The SNI tree on each listener stores a *borrowed* router pointer - * (and its own SSL_CTX_up_ref). pendingServerNames is the single - * owner — drop the borrowers first, then free the owner exactly - * once. The old loop deleted the router once per listener. */ - forEachListenSocket([&](us_listen_socket_t *ls) { - us_listen_socket_remove_server_name(ls, hostname_pattern.c_str()); - }); - for (auto it = pendingServerNames.begin(); it != pendingServerNames.end(); ) { - if (it->hostname == hostname_pattern) { - us_internal_ssl_ctx_unref(it->ctx); - delete it->router; - it = pendingServerNames.erase(it); - } else ++it; - } - } - return std::move(*this); - } - - TemplatedApp &&missingServerName(MoveOnlyFunction &&handler) { - if (!constructorFailed()) { - httpContext->getSocketContextData()->missingServerNameHandler = std::move(handler); - forEachListenSocket([&](us_listen_socket_t *ls) { - us_listen_socket_on_server_name(ls, &onMissingServerName); - }); - } - return std::move(*this); - } - - /* Returns the SSL_CTX* of this app, or nullptr. */ - void *getNativeHandle() { - return sslCtx; - } - /* Attaches a "filter" function to track socket connections/disconnections */ TemplatedApp &&filter(MoveOnlyFunction *, int)> &&filterHandler) { httpContext->filter(std::move(filterHandler)); @@ -320,21 +285,6 @@ struct TemplatedApp { TemplatedApp(TemplatedApp &&other) = delete; private: - static struct ssl_ctx_st *onMissingServerName(struct us_listen_socket_t *ls, const char *hostname, int *abort_handshake, struct us_socket_t *socket) { - /* Bun.serve's missingServerName handler registers a context or lets the - * default serve the request - it never aborts or suspends the handshake. */ - (void) abort_handshake; - (void) socket; - auto *httpContext = (HttpContext *) us_socket_group_ext(us_listen_socket_group(ls)); - httpContext->getSocketContextData()->missingServerNameHandler(hostname); - /* The handler is expected to have registered the name via - * addServerName(); hand the newly-registered context back so the - * in-flight handshake uses it (the resolver no longer re-checks the - * SNI tree after this callback returns). The handler may also have - * closed the listener, freeing the tree. */ - return us_listen_socket_find_server_name_ctx(ls, hostname); - } - TemplatedApp(SocketContextOptions options) { if constexpr (SSL) { enum create_bun_socket_error_t err = CREATE_BUN_SOCKET_ERROR_NONE; @@ -718,9 +668,6 @@ struct TemplatedApp { for (auto &p : pendingServerNames) { us_listen_socket_add_server_name(ls, p.hostname.c_str(), p.ctx, p.router); } - if (httpContext->getSocketContextData()->missingServerNameHandler) { - us_listen_socket_on_server_name(ls, &onMissingServerName); - } } return ls; } diff --git a/packages/bun-uws/src/AsyncSocket.h b/packages/bun-uws/src/AsyncSocket.h index e608eedf98d0..40ce1f568ace 100644 --- a/packages/bun-uws/src/AsyncSocket.h +++ b/packages/bun-uws/src/AsyncSocket.h @@ -202,28 +202,6 @@ struct AsyncSocket { return true; } - /* Returns the text representation of an IPv4 or IPv6 address */ - std::string_view addressAsText(std::string_view binary) { - static thread_local char buf[64]; - int ipLength = 0; - - if (!binary.length()) { - return {}; - } - - unsigned char *b = (unsigned char *) binary.data(); - - if (binary.length() == 4) { - ipLength = snprintf(buf, sizeof(buf), "%u.%u.%u.%u", b[0], b[1], b[2], b[3]); - } else { - ipLength = snprintf(buf, sizeof(buf), "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", - b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], - b[12], b[13], b[14], b[15]); - } - - return {buf, (unsigned int) ipLength}; - } - /* Returns the remote IP address or empty string on failure */ std::string_view getRemoteAddress() { static thread_local char buf[16]; @@ -232,11 +210,6 @@ struct AsyncSocket { return std::string_view(buf, (unsigned int) ipLength); } - /* Returns the text representation of IP */ - std::string_view getRemoteAddressAsText() { - return addressAsText(getRemoteAddress()); - } - /** * Flushes the socket buffer by writing as much data as possible to the underlying socket. * diff --git a/packages/bun-uws/src/AsyncSocketData.h b/packages/bun-uws/src/AsyncSocketData.h index 53bfb059d41d..f67645840930 100644 --- a/packages/bun-uws/src/AsyncSocketData.h +++ b/packages/bun-uws/src/AsyncSocketData.h @@ -44,7 +44,6 @@ struct BackPressure { /* Unsent bytes. data() points at length() contiguous bytes. */ size_t length() const { return tail - head; } - size_t size() const { return length(); } const char *data() const { return buf + head; } /* Allocation footprint for memoryCost / GC reporting. */ size_t totalLength() const { return cap; } diff --git a/packages/bun-uws/src/Http3App.h b/packages/bun-uws/src/Http3App.h index bde4a4828e01..cdd251cac60f 100644 --- a/packages/bun-uws/src/Http3App.h +++ b/packages/bun-uws/src/Http3App.h @@ -20,8 +20,6 @@ struct H3App { return new H3App{ctx}; } - bool constructorFailed() { return http3Context == nullptr; } - ~H3App() { if (http3Context) http3Context->free(); } @@ -60,7 +58,6 @@ struct H3App { memcpy(&raw, &options, sizeof(raw)); return http3Context->addServerName(hostname, raw); } - void *getNativeHandle() { return http3Context; } }; } diff --git a/packages/bun-uws/src/Http3Context.h b/packages/bun-uws/src/Http3Context.h index e7229b9b6754..d007e27b7692 100644 --- a/packages/bun-uws/src/Http3Context.h +++ b/packages/bun-uws/src/Http3Context.h @@ -1,6 +1,8 @@ #ifndef UWS_H3CONTEXT_H #define UWS_H3CONTEXT_H +#include + #include "quic.h" #include "Loop.h" #include "Http3ContextData.h" diff --git a/packages/bun-uws/src/Http3Request.h b/packages/bun-uws/src/Http3Request.h index ecb9dc270502..df8c33509cdb 100644 --- a/packages/bun-uws/src/Http3Request.h +++ b/packages/bun-uws/src/Http3Request.h @@ -2,7 +2,6 @@ #define UWS_H3REQUEST_H #include "quic.h" -#include "QueryParser.h" #include #include @@ -30,9 +29,6 @@ struct Http3Request { fullUrl = value; size_t q = value.find('?'); url = q == std::string_view::npos ? value : value.substr(0, q); - /* Keep the leading '?' — getDecodedQueryValue expects it and - * unconditionally drops the first byte. */ - query = q == std::string_view::npos ? std::string_view{} : value.substr(q); } else if (name == ":authority") { authority = value; } else if (authority.empty() && name.size() == 4 && equalsIgnoreCase(name, "host")) { @@ -51,10 +47,6 @@ struct Http3Request { std::string_view getUrl() { return url; } std::string_view getFullUrl() { return fullUrl; } - std::string_view getQuery() { return query.empty() ? query : query.substr(1); } - std::string_view getQuery(std::string_view key) { - return getDecodedQueryValue(key, query); - } /* HttpRequest::getMethod() lowercases in place; we own no writable * buffer, so write into a per-request scratch instead. */ @@ -112,7 +104,7 @@ struct Http3Request { const us_quic_header_t *headers; unsigned int headerCount; - std::string_view method, url, fullUrl, query, authority; + std::string_view method, url, fullUrl, authority; std::pair params{-1, nullptr}; char methodLower[32]; bool yield = false; diff --git a/packages/bun-uws/src/Http3Response.h b/packages/bun-uws/src/Http3Response.h index 3899700bd891..321388d11839 100644 --- a/packages/bun-uws/src/Http3Response.h +++ b/packages/bun-uws/src/Http3Response.h @@ -133,15 +133,12 @@ struct Http3Response { return !(getHttpResponseData()->state & Http3ResponseData::HTTP_RESPONSE_PENDING); } - uint64_t getWriteOffset() { return getHttpResponseData()->offset; } - void overrideWriteOffset(uint64_t o) { getHttpResponseData()->offset = o; } size_t getBufferedAmount() { return getHttpResponseData()->backpressure.length(); } Http3Response *pause() { us_quic_stream_want_read((us_quic_stream_t *) this, 0); return this; } Http3Response *resume() { us_quic_stream_want_read((us_quic_stream_t *) this, 1); return this; } Http3Response *cork(MoveOnlyFunction &&fn) { fn(); return this; } - void *getSocketData() { return getHttpResponseData()->socketData; } Http3Response *onWritable(void *userData, Http3ResponseData::OnWritableCallback h) { Http3ResponseData *d = getHttpResponseData(); diff --git a/packages/bun-uws/src/Http3ResponseData.h b/packages/bun-uws/src/Http3ResponseData.h index 1009bd7d2683..d9e1b49f864a 100644 --- a/packages/bun-uws/src/Http3ResponseData.h +++ b/packages/bun-uws/src/Http3ResponseData.h @@ -40,7 +40,6 @@ struct Http3ResponseData { * peer stalls or aborts mid-stream. Keep the onWritable context * pointer in its own slot, same as HttpResponseData. */ void *writableUserData = nullptr; - void *socketData = nullptr; OnWritableCallback onWritable = nullptr; OnAbortedCallback onAborted = nullptr; OnDataCallback inStream = nullptr; diff --git a/packages/bun-uws/src/HttpContextData.h b/packages/bun-uws/src/HttpContextData.h index 5239d62a1ebd..8d71584e7083 100644 --- a/packages/bun-uws/src/HttpContextData.h +++ b/packages/bun-uws/src/HttpContextData.h @@ -59,8 +59,6 @@ struct alignas(16) HttpContextData { using OnClientErrorCallback = MoveOnlyFunction; using OnSocketClosedCallback = void (*)(void* userData, int is_ssl, struct us_socket_t *rawSocket); - MoveOnlyFunction missingServerNameHandler; - struct RouterData { HttpResponse *httpResponse; HttpRequest *httpRequest; diff --git a/packages/bun-uws/src/HttpParser.h b/packages/bun-uws/src/HttpParser.h index 7925b43cdf92..1c47e4f39fa0 100644 --- a/packages/bun-uws/src/HttpParser.h +++ b/packages/bun-uws/src/HttpParser.h @@ -37,7 +37,6 @@ #include "ChunkedEncoding.h" #include "BloomFilter.h" -#include "QueryParser.h" #include "HttpErrors.h" #if defined(_WIN32) @@ -438,13 +437,6 @@ struct HttpResponseData; return headers->key; } - /* Finds and decodes the URI component. */ - std::string_view getQuery(std::string_view key) - { - /* Raw querystring including initial '?' sign */ - return getDecodedQueryValue(key, headers->value.substr(querySeparator)); - } - void setParameters(std::pair parameters) { currentParameters = parameters; diff --git a/packages/bun-uws/src/HttpResponse.h b/packages/bun-uws/src/HttpResponse.h index c556f4dece84..b2da9ee25af3 100644 --- a/packages/bun-uws/src/HttpResponse.h +++ b/packages/bun-uws/src/HttpResponse.h @@ -469,8 +469,6 @@ struct HttpResponse : public AsyncSocket { using Super::close; /* See AsyncSocket */ - using Super::getRemoteAddress; - using Super::getRemoteAddressAsText; using Super::getNativeHandle; /* Throttle reads and writes */ @@ -837,13 +835,6 @@ struct HttpResponse : public AsyncSocket { } } - /* Get the current byte write offset for this Http response */ - uint64_t getWriteOffset() { - HttpResponseData *httpResponseData = getHttpResponseData(); - - return httpResponseData->offset; - } - /* Checking if we have fully responded and are ready for another request */ bool hasResponded() { HttpResponseData *httpResponseData = getHttpResponseData(); @@ -967,22 +958,11 @@ struct HttpResponse : public AsyncSocket { data->received_bytes_per_timeout = 0; } - void* getSocketData() { - HttpResponseData *httpResponseData = getHttpResponseData(); - - return httpResponseData->socketData; - } bool isConnectRequest() { HttpResponseData *httpResponseData = getHttpResponseData(); return httpResponseData->isConnectRequest; } - void setWriteOffset(uint64_t offset) { - HttpResponseData *httpResponseData = getHttpResponseData(); - - httpResponseData->offset = offset; - } - }; } diff --git a/packages/bun-uws/src/Loop.h b/packages/bun-uws/src/Loop.h index e6c73e9508f7..a874b7e4567a 100644 --- a/packages/bun-uws/src/Loop.h +++ b/packages/bun-uws/src/Loop.h @@ -30,20 +30,9 @@ extern "C" int bun_is_exiting(); namespace uWS { struct Loop { private: + /* us_wakeup_loop only interrupts the poll; nothing is queued for this callback to run. */ static void wakeupCb(us_loop_t *loop) { - LoopData *loopData = (LoopData *) us_loop_ext(loop); - - /* Swap current deferQueue */ - loopData->deferMutex.lock(); - int oldDeferQueue = loopData->currentDeferQueue; - loopData->currentDeferQueue = (loopData->currentDeferQueue + 1) % 2; - loopData->deferMutex.unlock(); - - /* Drain the queue */ - for (auto &x : loopData->deferQueues[oldDeferQueue]) { - x(); - } - loopData->deferQueues[oldDeferQueue].clear(); + (void) loop; } static void preCb(us_loop_t *loop) { @@ -177,18 +166,6 @@ struct Loop { loopData->preHandlers.erase(key); } - /* Defer this callback on Loop's thread of execution */ - void defer(MoveOnlyFunction &&cb) { - LoopData *loopData = (LoopData *) us_loop_ext((us_loop_t *) this); - - //if (std::thread::get_id() == ) // todo: add fast path for same thread id - loopData->deferMutex.lock(); - loopData->deferQueues[loopData->currentDeferQueue].emplace_back(std::move(cb)); - loopData->deferMutex.unlock(); - - us_wakeup_loop((us_loop_t *) this); - } - /* Actively block and run this loop */ void run() { us_loop_run((us_loop_t *) this); diff --git a/packages/bun-uws/src/LoopData.h b/packages/bun-uws/src/LoopData.h index 3f223c07b687..9bbfbee8db42 100644 --- a/packages/bun-uws/src/LoopData.h +++ b/packages/bun-uws/src/LoopData.h @@ -22,9 +22,6 @@ #include #include #include -#include -#include -#include #include @@ -39,10 +36,6 @@ struct Loop; struct alignas(16) LoopData { friend struct Loop; private: - std::mutex deferMutex; - int currentDeferQueue = 0; - std::vector> deferQueues[2]; - /* Map from void ptr to handler */ std::map> postHandlers, preHandlers; diff --git a/packages/bun-uws/src/QueryParser.h b/packages/bun-uws/src/QueryParser.h deleted file mode 100644 index 55e504acc5f1..000000000000 --- a/packages/bun-uws/src/QueryParser.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Authored by Alex Hultman, 2018-2020. - * Intellectual property of third-party. - - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - - * http://www.apache.org/licenses/LICENSE-2.0 - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* This module implements URI query parsing and retrieval of value given key */ - -#ifndef UWS_QUERYPARSER_H -#define UWS_QUERYPARSER_H - -#include - -namespace uWS { - - /* Takes raw query including initial '?' sign. Will inplace decode, so input will mutate */ - static inline std::string_view getDecodedQueryValue(std::string_view key, std::string_view rawQuery) { - - /* Can't have a value without a key */ - if (!key.length()) { - return {}; - } - - /* Start with the whole querystring including initial '?' */ - std::string_view queryString = rawQuery; - - /* List of key, value could be cached for repeated fetches similar to how headers are, todo! */ - while (queryString.length()) { - /* Find boundaries of this statement */ - std::string_view statement = queryString.substr(1, queryString.find('&', 1) - 1); - - /* Only bother if first char of key match (early exit) */ - if (statement.length() && statement[0] == key[0]) { - /* Equal sign must be present and not in the end of statement */ - auto equality = statement.find('='); - if (equality != std::string_view::npos) { - - std::string_view statementKey = statement.substr(0, equality); - std::string_view statementValue = statement.substr(equality + 1); - - /* String comparison */ - if (key == statementKey) { - - /* Decode value inplace, put null at end if before length of original */ - char *in = (char *) statementValue.data(); - - /* Write offset */ - unsigned int out = 0; - - /* Walk over all chars until end or null char, decoding in place */ - for (unsigned int i = 0; i < statementValue.length() && in[i]; i++) { - /* Only bother with '%' */ - if (in[i] == '%') { - /* Do we have enough data for two bytes hex? */ - if (i + 2 >= statementValue.length()) { - return {}; - } - - /* Two bytes hex */ - int hex1 = in[i + 1] - '0'; - if (hex1 > 9) { - hex1 &= 223; - hex1 -= 7; - } - - int hex2 = in[i + 2] - '0'; - if (hex2 > 9) { - hex2 &= 223; - hex2 -= 7; - } - - *((unsigned char *) &in[out]) = (unsigned char) (hex1 * 16 + hex2); - i += 2; - } else { - /* Is this even a rule? */ - if (in[i] == '+') { - in[out] = ' '; - } else { - in[out] = in[i]; - } - } - - /* We always only write one char */ - out++; - } - - /* If decoded string is shorter than original, put null char to stop next read */ - if (out < statementValue.length()) { - in[out] = 0; - } - - return statementValue.substr(0, out); - } - } else { - /* This querystring is invalid, cannot parse it */ - return {nullptr, 0}; - } - } - - queryString.remove_prefix(statement.length() + 1); - } - - /* Nothing found is given as nullptr, while empty string is given as some pointer to the given buffer */ - return {nullptr, 0}; - } - -} - -#endif diff --git a/packages/bun-uws/src/WebSocket.h b/packages/bun-uws/src/WebSocket.h index 775097e22868..401f64699bc8 100644 --- a/packages/bun-uws/src/WebSocket.h +++ b/packages/bun-uws/src/WebSocket.h @@ -59,8 +59,6 @@ struct WebSocket : AsyncSocket { /* See AsyncSocket */ using Super::getBufferedAmount; using Super::getRemoteAddress; - using Super::getRemoteAddressAsText; - using Super::getNativeHandle; /* WebSocket close cannot be an alias to AsyncSocket::close since * we need to check first if it was shut down by remote peer */ @@ -110,20 +108,6 @@ struct WebSocket : AsyncSocket { return Super::getAsyncSocketData()->buffer.totalLength() + sizeof(WebSocket); } - /* Sending fragmented messages puts a bit of effort on the user; you must not interleave regular sends - * with fragmented sends and you must sendFirstFragment, [sendFragment], then finally sendLastFragment. */ - SendStatus sendFirstFragment(std::string_view message, OpCode opCode = OpCode::BINARY, bool compress = false) { - return send(message, opCode, compress, false); - } - - SendStatus sendFragment(std::string_view message, bool compress = false) { - return send(message, CONTINUATION, compress, false); - } - - SendStatus sendLastFragment(std::string_view message, bool compress = false) { - return send(message, CONTINUATION, compress, true); - } - /* Send or buffer a WebSocket frame, compressed or not. Returns BACKPRESSURE on increased user space backpressure, * DROPPED on dropped message (due to backpressure) or SUCCCESS if you are free to send even more now. */ SendStatus send(std::string_view message, OpCode opCode = OpCode::BINARY, bool compress = false, bool fin = true) { diff --git a/packages/bun-uws/src/WebSocketProtocol.h b/packages/bun-uws/src/WebSocketProtocol.h index 1947efa57d03..a604dc495a9c 100644 --- a/packages/bun-uws/src/WebSocketProtocol.h +++ b/packages/bun-uws/src/WebSocketProtocol.h @@ -35,7 +35,6 @@ inline constexpr std::string_view ERR_TOO_BIG_MESSAGE("Received too big message" inline constexpr std::string_view ERR_WEBSOCKET_TIMEOUT("WebSocket timed out from inactivity"); inline constexpr std::string_view ERR_INVALID_TEXT("Received invalid UTF-8"); inline constexpr std::string_view ERR_TOO_BIG_MESSAGE_INFLATION("Received too big message, or other inflation error"); -inline constexpr std::string_view ERR_INVALID_CLOSE_PAYLOAD("Received invalid close payload"); inline constexpr std::string_view ERR_INVALID_MASKING("Received an incorrectly masked frame"); inline constexpr std::string_view ERR_INVALID_RSV1("Received unexpected RSV1 bit"); @@ -48,17 +47,10 @@ enum OpCode : unsigned char { PONG = 10 }; -enum { - CLIENT, - SERVER -}; - // 24 bytes perfectly template struct WebSocketState { public: - static constexpr unsigned int SHORT_MESSAGE_HEADER = isServer ? 6 : 2; - static constexpr unsigned int MEDIUM_MESSAGE_HEADER = isServer ? 8 : 4; static constexpr unsigned int LONG_MESSAGE_HEADER = isServer ? 14 : 10; // 16 bytes @@ -168,8 +160,6 @@ static inline size_t messageFrameSize(size_t messageSize) { } enum { - SND_CONTINUATION = 1, - SND_NO_FIN = 2, SND_COMPRESSED = 64 }; @@ -393,10 +383,6 @@ struct WebSocketProtocol { } public: - WebSocketProtocol() { - - } - static inline void consume(char *src, unsigned int length, WebSocketState *wState, void *user) { if (wState->state.spillLength) { src -= wState->state.spillLength; @@ -462,8 +448,6 @@ struct WebSocketProtocol { } } - static constexpr int CONSUME_POST_PADDING = 4; - static constexpr int CONSUME_PRE_PADDING = LONG_MESSAGE_HEADER - 1; }; } diff --git a/src/bun_core/util.rs b/src/bun_core/util.rs index 818e0a72ad09..f2e03a606767 100644 --- a/src/bun_core/util.rs +++ b/src/bun_core/util.rs @@ -5279,8 +5279,6 @@ pub mod perf { unsafe extern "C" { /// No preconditions; returns 0/1 based on tracefs availability. pub safe fn Bun__linux_trace_init() -> core::ffi::c_int; - /// No preconditions. - pub safe fn Bun__linux_trace_close(); pub fn Bun__linux_trace_emit( event_name: *const core::ffi::c_char, duration_ns: i64, diff --git a/src/bundler/Cargo.toml b/src/bundler/Cargo.toml index 3f9660ede8ff..a71b0cc57659 100644 --- a/src/bundler/Cargo.toml +++ b/src/bundler/Cargo.toml @@ -16,7 +16,6 @@ bun_dispatch.workspace = true strum.workspace = true bstr.workspace = true scopeguard.workspace = true -const_format.workspace = true enum-map.workspace = true bitflags.workspace = true thiserror.workspace = true diff --git a/src/bunfig/Cargo.toml b/src/bunfig/Cargo.toml index 114e62a778f2..86bcececbd83 100644 --- a/src/bunfig/Cargo.toml +++ b/src/bunfig/Cargo.toml @@ -17,7 +17,6 @@ workspace = true bun_io.workspace = true bstr.workspace = true scopeguard.workspace = true -enum-map.workspace = true thiserror.workspace = true bun_alloc.workspace = true bun_api.workspace = true diff --git a/src/collections/Cargo.toml b/src/collections/Cargo.toml index 5c7da9258b7c..32e9732b98ee 100644 --- a/src/collections/Cargo.toml +++ b/src/collections/Cargo.toml @@ -10,7 +10,6 @@ path = "lib.rs" workspace = true [dependencies] -strum.workspace = true # `raw-entry` powers `StringHashMap::{get_hashed, put_static_key_hashed}` — the # precomputed-hash probe/insert path the resolver's `DirEntry::add_entry` hot # loop uses so it hashes each basename once instead of on every lookup + insert. @@ -29,6 +28,5 @@ bun_wyhash.workspace = true bun_ptr.workspace = true rustc-hash = "2" -thiserror.workspace = true bun_simdutf_sys.workspace = true diff --git a/src/crash_handler/Cargo.toml b/src/crash_handler/Cargo.toml index 3d39572bf8ce..ca50e8f7086f 100644 --- a/src/crash_handler/Cargo.toml +++ b/src/crash_handler/Cargo.toml @@ -13,7 +13,6 @@ workspace = true thiserror.workspace = true bun_errno.workspace = true bstr.workspace = true -scopeguard.workspace = true const_format.workspace = true libc.workspace = true bitflags.workspace = true diff --git a/src/css/Cargo.toml b/src/css/Cargo.toml index a59b7543ac7e..532247f8a73a 100644 --- a/src/css/Cargo.toml +++ b/src/css/Cargo.toml @@ -14,12 +14,7 @@ thiserror.workspace = true strum.workspace = true bstr.workspace = true scopeguard.workspace = true -const_format.workspace = true -enum-map.workspace = true -enumset.workspace = true -libc.workspace = true bitflags.workspace = true -typed-arena.workspace = true bun_base64.workspace = true bun_alloc.workspace = true bun_core.workspace = true diff --git a/src/http/Cargo.toml b/src/http/Cargo.toml index da1bf1993a4d..14a66b926596 100644 --- a/src/http/Cargo.toml +++ b/src/http/Cargo.toml @@ -14,7 +14,6 @@ bun_errno.workspace = true thiserror.workspace = true strum.workspace = true bstr.workspace = true -scopeguard.workspace = true bun_analytics.workspace = true bun_base64.workspace = true bun_boringssl.workspace = true diff --git a/src/http/h3_client/ClientContext.rs b/src/http/h3_client/ClientContext.rs index 0023813d30fe..33b2823d43de 100644 --- a/src/http/h3_client/ClientContext.rs +++ b/src/http/h3_client/ClientContext.rs @@ -2,7 +2,7 @@ //! client engine and the live-session registry. Never freed — the engine //! lives for the process, same as the HTTP thread itself. -use core::ffi::{c_uint, c_void}; +use core::ffi::c_uint; use core::ptr::NonNull; use core::sync::atomic::Ordering; @@ -139,9 +139,7 @@ impl ClientContext { self.sessions.push(session); session_mut(session).enqueue(client); - let result = - self.qctx_mut() - .connect(host_z, port, host_z, reject, session.cast::()); + let result = self.qctx_mut().connect(host_z, port, host_z, reject); match result { ConnectResult::Socket(qs) => { session_mut(session).qsocket = NonNull::new(qs); diff --git a/src/ini/Cargo.toml b/src/ini/Cargo.toml index 86e1d9010866..9b9161c1e866 100644 --- a/src/ini/Cargo.toml +++ b/src/ini/Cargo.toml @@ -17,7 +17,6 @@ bun_base64.workspace = true bun_dotenv.workspace = true bun_install_types.workspace = true bun_parsers.workspace = true -bun_js_parser.workspace = true bun_alloc.workspace = true bun_core.workspace = true bun_collections.workspace = true diff --git a/src/install/Cargo.toml b/src/install/Cargo.toml index a8a45c65c7e7..67346c33151a 100644 --- a/src/install/Cargo.toml +++ b/src/install/Cargo.toml @@ -64,6 +64,5 @@ bun_sys.workspace = true bun_threading.workspace = true bun_transpiler.workspace = true bun_url.workspace = true -bun_uws.workspace = true bun_which.workspace = true bun_wyhash.workspace = true diff --git a/src/io/Cargo.toml b/src/io/Cargo.toml index 162e1fb7abfc..ef315b5137cb 100644 --- a/src/io/Cargo.toml +++ b/src/io/Cargo.toml @@ -11,12 +11,9 @@ workspace = true [dependencies] thiserror.workspace = true -bun_opaque.workspace = true strum.workspace = true bstr.workspace = true scopeguard.workspace = true -const_format.workspace = true -enum-map.workspace = true enumset.workspace = true libc.workspace = true bitflags.workspace = true @@ -27,6 +24,5 @@ bun_collections.workspace = true bun_spawn_sys.workspace = true bun_sys.workspace = true bun_uws_sys.workspace = true -bun_paths.workspace = true bun_errno.workspace = true bun_threading.workspace = true diff --git a/src/js_printer/Cargo.toml b/src/js_printer/Cargo.toml index 1265a6f47d61..6424f2ffd7b6 100644 --- a/src/js_printer/Cargo.toml +++ b/src/js_printer/Cargo.toml @@ -13,8 +13,6 @@ workspace = true bytemuck = "1" thiserror.workspace = true bstr.workspace = true -scopeguard.workspace = true -const_format.workspace = true enum-map.workspace = true enumset.workspace = true bun_alloc.workspace = true diff --git a/src/js_printer/lib.rs b/src/js_printer/lib.rs index e0b02267e024..9764eda8258d 100644 --- a/src/js_printer/lib.rs +++ b/src/js_printer/lib.rs @@ -7023,9 +7023,6 @@ pub trait WriterContext { fn advance_by(&mut self, count: u64); fn slice(&self) -> &[u8]; fn take_buffer(&mut self) -> MutableString; - fn flush(&mut self) -> crate::Result<()> { - Ok(()) - } fn done(&mut self) -> crate::Result<()> { Ok(()) } @@ -7165,9 +7162,6 @@ impl Writer { } } - pub fn flush(&mut self) -> crate::Result<()> { - self.ctx.flush() - } pub(crate) fn done(&mut self) -> crate::Result<()> { self.ctx.done() } @@ -7397,10 +7391,6 @@ impl BufferWriter { self.written_len = self.buffer.list.len(); Ok(()) } - - pub(crate) fn flush(&mut self) -> crate::Result<()> { - Ok(()) - } } impl WriterContext for BufferWriter { @@ -7437,10 +7427,6 @@ impl WriterContext for BufferWriter { self.take_buffer() } #[inline] - fn flush(&mut self) -> crate::Result<()> { - self.flush() - } - #[inline] fn done(&mut self) -> crate::Result<()> { self.done() } diff --git a/src/jsc/Cargo.toml b/src/jsc/Cargo.toml index e79a564a6a5a..ba45cb0f3fd3 100644 --- a/src/jsc/Cargo.toml +++ b/src/jsc/Cargo.toml @@ -51,7 +51,6 @@ bun_sourcemap.workspace = true bun_spawn.workspace = true bun_sys.workspace = true bun_threading.workspace = true -bun_transpiler.workspace = true bun_url.workspace = true bun_uws.workspace = true bun_watcher.workspace = true diff --git a/src/jsc/NodeModuleModule.rs b/src/jsc/NodeModuleModule.rs index 1b31bb6a44a5..c6873982fda1 100644 --- a/src/jsc/NodeModuleModule.rs +++ b/src/jsc/NodeModuleModule.rs @@ -124,24 +124,6 @@ impl Default for CustomLoader { } } -// `JSGlobalObject` is an opaque `UnsafeCell`-backed ZST handle; remaining -// params are by-value `JSValue`/scalars → `safe fn`. -unsafe extern "C" { - pub safe fn JSCommonJSExtensions__appendFunction( - global: &JSGlobalObject, - value: JSValue, - ) -> u32; - pub safe fn JSCommonJSExtensions__setFunction( - global: &JSGlobalObject, - index: u32, - value: JSValue, - ); - /// Returns the index of the last value, which must have it's references updated to `index` - pub safe fn JSCommonJSExtensions__swapRemove(global: &JSGlobalObject, index: u32) -> u32; -} - -// Memory management is complicated because JSValues are stored in gc-visitable -// WriteBarriers in C++ but the hash map for extensions is in Rust for flexibility. fn on_require_extension_modify( global: &JSGlobalObject, str: &[u8], diff --git a/src/jsc/TopExceptionScope.rs b/src/jsc/TopExceptionScope.rs index 3c40fbc982a7..d8feaf4c62b6 100644 --- a/src/jsc/TopExceptionScope.rs +++ b/src/jsc/TopExceptionScope.rs @@ -259,13 +259,7 @@ impl TopExceptionScope { NonNull::new(TopExceptionScope__pureException(&mut self.bytes)) } - pub fn clear_exception(&mut self) { - #[cfg(any(debug_assertions, bun_asan))] - debug_assert!(core::ptr::eq(self.location, &raw const self.bytes[0])); - TopExceptionScope__clearException(&mut self.bytes) - } - - /// As `clear_exception`, but a TerminationException stays pending (JSC's + /// Clears a pending exception, but a TerminationException stays pending (JSC's /// `clearExceptionExceptTermination`): it belongs to whoever is unwinding above. pub fn clear_exception_except_termination(&mut self) { #[cfg(any(debug_assertions, bun_asan))] @@ -741,7 +735,6 @@ unsafe extern "C" { /// only returns exceptions that have already been thrown. does not check traps safe fn TopExceptionScope__pureException(ptr: &mut [u8; SIZE]) -> *mut Exception; safe fn TopExceptionScope__takeTerminationOutsideScript(ptr: &mut [u8; SIZE]) -> bool; - safe fn TopExceptionScope__clearException(ptr: &mut [u8; SIZE]); safe fn TopExceptionScope__clearExceptionExceptTermination(ptr: &mut [u8; SIZE]); /// returns if an exception was already thrown, or if a trap (like another thread requesting /// termination) causes an exception to be thrown diff --git a/src/jsc/bindings/JSCommonJSExtensions.cpp b/src/jsc/bindings/JSCommonJSExtensions.cpp index 73177edba7c0..4dece4f37e58 100644 --- a/src/jsc/bindings/JSCommonJSExtensions.cpp +++ b/src/jsc/bindings/JSCommonJSExtensions.cpp @@ -204,39 +204,6 @@ bool JSCommonJSExtensions::deleteProperty(JSC::JSCell* cell, JSC::JSGlobalObject return deleted; } -extern "C" uint32_t JSCommonJSExtensions__appendFunction(Zig::GlobalObject* globalObject, JSC::JSValue value) -{ - JSCommonJSExtensions* extensions = globalObject->lazyRequireExtensionsObject(); - extensions->m_registeredFunctions.append(JSC::WriteBarrier()); - extensions->m_registeredFunctions.last().set(globalObject->vm(), extensions, value); - return extensions->m_registeredFunctions.size() - 1; -} - -extern "C" void JSCommonJSExtensions__setFunction(Zig::GlobalObject* globalObject, uint32_t index, JSC::JSValue value) -{ - JSCommonJSExtensions* extensions = globalObject->lazyRequireExtensionsObject(); - extensions->m_registeredFunctions[index].set(globalObject->vm(), globalObject, value); -} - -extern "C" uint32_t JSCommonJSExtensions__swapRemove(Zig::GlobalObject* globalObject, uint32_t index) -{ - JSCommonJSExtensions* extensions = globalObject->lazyRequireExtensionsObject(); - ASSERT(extensions->m_registeredFunctions.size() > 0); - if (extensions->m_registeredFunctions.size() == 1) { - extensions->m_registeredFunctions.clear(); - return index; - } - ASSERT(index < extensions->m_registeredFunctions.size()); - if (index < (extensions->m_registeredFunctions.size() - 1)) { - JSValue last = extensions->m_registeredFunctions.takeLast().get(); - extensions->m_registeredFunctions[index].set(globalObject->vm(), globalObject, last); - return extensions->m_registeredFunctions.size(); - } else { - extensions->m_registeredFunctions.removeLast(); - return index; - } -} - // This implements `Module._extensions['.js']`, which // - Loads source code from a file // - [not supported] Calls `fs.readFileSync`, which is usually not overridden. @@ -297,18 +264,4 @@ JSC::EncodedJSValue builtinLoader(JSC::JSGlobalObject* globalObject, JSC::CallFr return JSC::JSValue::encode(jsUndefined()); } -template -void JSCommonJSExtensions::visitChildrenImpl(JSCell* cell, Visitor& visitor) -{ - JSCommonJSExtensions* thisObject = uncheckedDowncast(cell); - ASSERT_GC_OBJECT_INHERITS(thisObject, info()); - Base::visitChildren(thisObject, visitor); - - for (auto& func : thisObject->m_registeredFunctions) { - visitor.append(func); - } -} - -DEFINE_VISIT_CHILDREN(JSCommonJSExtensions); - } // namespace Bun diff --git a/src/jsc/bindings/JSCommonJSExtensions.h b/src/jsc/bindings/JSCommonJSExtensions.h index 4adccd6e4f96..28ffd42fe529 100644 --- a/src/jsc/bindings/JSCommonJSExtensions.h +++ b/src/jsc/bindings/JSCommonJSExtensions.h @@ -12,8 +12,6 @@ class JSCommonJSExtensions : public JSC::JSDestructibleObject { static constexpr unsigned StructureFlags = Base::StructureFlags | JSC::OverridesPut; ~JSCommonJSExtensions(); - WTF::Vector> m_registeredFunctions; - static JSCommonJSExtensions* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) { JSCommonJSExtensions* ptr = new (NotNull, JSC::allocateCell(vm)) JSCommonJSExtensions(vm, structure); @@ -36,8 +34,6 @@ class JSCommonJSExtensions : public JSC::JSDestructibleObject { return Bun::createClassStructure(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); } - DECLARE_VISIT_CHILDREN; - protected: static bool defineOwnProperty(JSC::JSObject*, JSC::JSGlobalObject*, JSC::PropertyName, const JSC::PropertyDescriptor&, bool shouldThrow); static bool put(JSC::JSCell*, JSC::JSGlobalObject*, JSC::PropertyName, JSC::JSValue, JSC::PutPropertySlot&); diff --git a/src/jsc/bindings/TopExceptionScopeBinding.cpp b/src/jsc/bindings/TopExceptionScopeBinding.cpp index 46bf64a1a16b..b2a059dd5bd0 100644 --- a/src/jsc/bindings/TopExceptionScopeBinding.cpp +++ b/src/jsc/bindings/TopExceptionScopeBinding.cpp @@ -64,13 +64,6 @@ extern "C" bool TopExceptionScope__takeTerminationOutsideScript(void* ptr) return Bun::takeTerminationOutsideScript(scope->vm(), *scope); } -extern "C" void TopExceptionScope__clearException(void* ptr) -{ - ASSERT((uintptr_t)ptr % alignof(TopExceptionScope) == 0); - auto* scope = static_cast(ptr); - scope->clearException(); -} - extern "C" void TopExceptionScope__clearExceptionExceptTermination(void* ptr) { ASSERT((uintptr_t)ptr % alignof(TopExceptionScope) == 0); diff --git a/src/jsc/bindings/linux_perf_tracing.cpp b/src/jsc/bindings/linux_perf_tracing.cpp index 07187ca171fc..e15d06332111 100644 --- a/src/jsc/bindings/linux_perf_tracing.cpp +++ b/src/jsc/bindings/linux_perf_tracing.cpp @@ -39,15 +39,6 @@ int Bun__linux_trace_init() return (trace_fd != -1) ? 1 : 0; } -// Close the trace file descriptor -void Bun__linux_trace_close() -{ - if (trace_fd != -1) { - close(trace_fd); - trace_fd = -1; - } -} - // Write a trace event to the trace marker // Format: "C|PID|EventName|DurationInNs" int Bun__linux_trace_emit(const char* event_name, int64_t duration_ns) diff --git a/src/libuv_sys/Cargo.toml b/src/libuv_sys/Cargo.toml index 7ed649605ed6..e173288fd72b 100644 --- a/src/libuv_sys/Cargo.toml +++ b/src/libuv_sys/Cargo.toml @@ -11,7 +11,6 @@ workspace = true [dependencies] strum.workspace = true -libc.workspace = true [target.'cfg(windows)'.dependencies] bun_windows_sys.workspace = true diff --git a/src/lsquic_sys/lib.rs b/src/lsquic_sys/lib.rs index 8f2c5da59b80..b1632d8052bb 100644 --- a/src/lsquic_sys/lib.rs +++ b/src/lsquic_sys/lib.rs @@ -206,7 +206,6 @@ unsafe extern "C" { ) -> *mut lsquic_engine; pub fn us_nq_spec_dest(s: *const lsquic_out_spec) -> *const sockaddr; pub fn us_nq_spec_local(s: *const lsquic_out_spec) -> *const sockaddr; - pub fn us_nq_spec_peer_ctx(s: *const lsquic_out_spec) -> *mut c_void; pub fn us_nq_spec_iov(s: *const lsquic_out_spec, n: *mut usize) -> *const iovec; pub fn us_nq_spec_stride() -> usize; pub fn us_nq_stream_reset(s: *mut lsquic_stream, code: u64); diff --git a/src/platform/Cargo.toml b/src/platform/Cargo.toml index 4f7c35a15f3f..82d8c036b0e2 100644 --- a/src/platform/Cargo.toml +++ b/src/platform/Cargo.toml @@ -11,4 +11,3 @@ workspace = true [dependencies] libc.workspace = true -bun_core.workspace = true diff --git a/src/ptr/Cargo.toml b/src/ptr/Cargo.toml index 79b19bede8d0..114def744340 100644 --- a/src/ptr/Cargo.toml +++ b/src/ptr/Cargo.toml @@ -11,7 +11,6 @@ workspace = true [dependencies] bstr.workspace = true -scopeguard.workspace = true bun_alloc.workspace = true bun_core.workspace = true bun_core_macros.workspace = true diff --git a/src/uws_sys/libuwsockets.cpp b/src/uws_sys/libuwsockets.cpp index 5c1e40665e62..f3c2b0ceecfa 100644 --- a/src/uws_sys/libuwsockets.cpp +++ b/src/uws_sys/libuwsockets.cpp @@ -1701,7 +1701,6 @@ __attribute__((callback (corker, ctx))) // This function is manual inlining + modification of // us_socket_remote_address // AsyncSocket::getRemoteAddress - // AsyncSocket::addressAsText // To get { ip, port, is_ipv6 } for Bun.serve().requestIP() static thread_local char b[64]; auto length = us_get_remote_address_info(b, (us_socket_t *)res, dest, port, (int*)is_ipv6); diff --git a/src/uws_sys/quic/Context.rs b/src/uws_sys/quic/Context.rs index 880c6091783a..cc452e5ab26d 100644 --- a/src/uws_sys/quic/Context.rs +++ b/src/uws_sys/quic/Context.rs @@ -2,7 +2,7 @@ //! For the client there is exactly one of these per HTTP-thread loop and it //! lives for the process; the server creates one per `Bun.serve({http3:true})`. -use core::ffi::{CStr, c_char, c_int, c_uint, c_void}; +use core::ffi::{CStr, c_char, c_int, c_uint}; use crate::Loop; use crate::quic::{PendingConnect, Socket, Stream}; @@ -31,7 +31,6 @@ unsafe extern "C" { reject_unauthorized: c_int, out_qs: *mut *mut Socket, out_pending: *mut *mut PendingConnect, - user: *mut c_void, ) -> c_int; safe fn us_quic_socket_context_on_hsk_done( @@ -110,7 +109,6 @@ impl Context { port: u16, sni: &CStr, reject_unauthorized: bool, - user: *mut c_void, ) -> ConnectResult { let mut qs: *mut Socket = core::ptr::null_mut(); let mut pc: *mut PendingConnect = core::ptr::null_mut(); @@ -124,7 +122,6 @@ impl Context { reject_unauthorized as c_int, &raw mut qs, &raw mut pc, - user, ) }; match rc { diff --git a/src/uws_sys/quic/Socket.rs b/src/uws_sys/quic/Socket.rs index 692510ffec03..e0a9ce442608 100644 --- a/src/uws_sys/quic/Socket.rs +++ b/src/uws_sys/quic/Socket.rs @@ -51,7 +51,7 @@ impl Socket { } /// `conn_ext_size` bytes of caller storage co-allocated with the socket. - /// Unset until the caller writes to it after `connect`/`on_open`; the + /// Unset until the caller writes to it after `connect`; the /// `Option>` slot pattern lets callbacks early-return on a null ext. #[inline] pub fn ext(&mut self) -> &mut Option> { diff --git a/test/js/node/module/require-extensions.test.ts b/test/js/node/module/require-extensions.test.ts index 7ca6fd493c20..45f5225b3ae2 100644 --- a/test/js/node/module/require-extensions.test.ts +++ b/test/js/node/module/require-extensions.test.ts @@ -1,6 +1,6 @@ import assert from "assert"; import { expect, mock, test } from "bun:test"; -import { tempDir } from "harness"; +import { bunEnv, bunExe, tempDir } from "harness"; import path from "path"; test("require.extensions shape makes sense", () => { @@ -162,6 +162,59 @@ test("wrapping an existing extension but it's secretly sync esm", () => { require.extensions[".cjs"] = original; } }); +test("a custom extension handler stays alive and current across GC", async () => { + using dir = tempDir("require-extensions-gc", { + "lib.custom": `module.exports = "plain js";`, + "main.js": ` + const calls = []; + function install(name) { + // Once this returns, the extensions table is the only thing that can + // keep the handler alive. + require.extensions[".custom"] = function (module, filename) { + calls.push(name); + module._compile("module.exports = " + JSON.stringify(name) + ";", filename); + }; + } + const reload = () => { + delete require.cache[require.resolve("./lib.custom")]; + return require("./lib.custom"); + }; + + install("first"); + Bun.gc(true); + const handler = require.extensions[".custom"]; + Bun.gc(true); + const first = reload(); + + install("second"); + Bun.gc(true); + const second = reload(); + const replaced = require.extensions[".custom"] !== handler; + + delete require.extensions[".custom"]; + Bun.gc(true); + const fallback = reload(); + + console.log(JSON.stringify({ first, second, replaced, fallback, calls })); + `, + }); + await using proc = Bun.spawn({ + cmd: [bunExe(), "main.js"], + env: bunEnv, + cwd: String(dir), + stderr: "pipe", + }); + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + expect(stderr).toBe(""); + expect(JSON.parse(stdout)).toEqual({ + first: "first", + second: "second", + replaced: true, + fallback: "plain js", + calls: ["first", "second"], + }); + expect(exitCode).toBe(0); +}); test("mutating extensions is banned by some files", () => { // vercel is not allowed to mutate require.extensions const files = ["node_modules/next/dist/build/next-config-ts/index.js", "node_modules/@meteorjs/babel/index.js"];