Compare commits

...
Author SHA1 Message Date
Jade Ellis 5ad36c0914 refactor(core): Drop hot reload support
This was unused and a hotbed of potential issues
2026-11-21 18:04:50 +00:00
Jade Ellis 7e678869ec refactor(core): Remove unneeded unsafe in UnwrapInfallible and Unquoted 2026-11-21 18:04:50 +00:00
Jade Ellis 9744a6e332 fix(core): Reject non-ELF targets in mod_init! and mod_fini! macros 2026-11-21 18:04:50 +00:00
Jade Ellis 306be392ba fix(core): Mark dlopen/dlsym wrappers unsafe in core::mods 2026-11-21 18:04:50 +00:00
Jade Ellis 66dd3e8e3e fix(service): Mark state::create unsafe and document lifetime invariants 2026-11-21 18:04:49 +00:00
Jade Ellis 1dd572416b docs(database): Document borrowed-item soundness flaw on iterator streams 2026-11-21 18:04:49 +00:00
Jade Ellis d74275bda1 refactor(database): Remove disabled unsound cfg(disable) blocks 2026-11-21 18:04:49 +00:00
Jade Ellis 65d25c77e8 fix(database): Assert ColumnFamily layout and document Map drop order 2026-11-21 18:04:48 +00:00
Jade Ellis 95f925eaee fix(database): Fix Seek drop order and remove no-op transmute in pool 2026-11-21 18:04:48 +00:00
Jade Ellis becfc2454f fix(core): Fix UAF race and aliasing UB in config::Manager 2026-11-21 18:04:48 +00:00
Jade Ellis b617e9fd5c fix(core): Remove unsound assert_unchecked in compute::getcpu 2026-11-21 18:04:48 +00:00
Jade Ellis ece207286a fix(core): Fix UB in usize_from_f64 on non-finite and out-of-range floats 2026-11-21 18:04:47 +00:00
Renovate Bot fda99bcda2 chore(deps): update dependency cargo-bins/cargo-binstall to v1.28.0 2026-11-21 16:08:11 +00:00
Erwan Leboucher 5d66476126 fix(metrics): Fix in-flight requests, PDU lag, latency buckets and thumbnail accounting 2026-11-21 16:06:51 +00:00
Renovate Bot 798bef5bc7 chore(deps): update node-patch-updates to v2.1.4 2026-11-21 16:03:41 +00:00
Ginger 7408d53977 chore: News fragment 2026-11-21 16:03:31 +00:00
Ginger 973cfd5746 fix: Log OIDC registrations in the admin room 2026-11-21 16:03:31 +00:00
55 changed files with 508 additions and 1121 deletions

No files matched your search

Generated
+3 -15
View File
@@ -759,7 +759,7 @@ checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a"
dependencies = [ dependencies = [
"glob", "glob",
"libc", "libc",
"libloading 0.8.9", "libloading",
] ]
[[package]] [[package]]
@@ -997,7 +997,6 @@ dependencies = [
"ipaddress", "ipaddress",
"lettre", "lettre",
"libc", "libc",
"libloading 0.9.1",
"libmimalloc-sys", "libmimalloc-sys",
"lock_api 0.5.0", "lock_api 0.5.0",
"maplit", "maplit",
@@ -3241,16 +3240,6 @@ dependencies = [
"windows-link", "windows-link",
] ]
[[package]]
name = "libloading"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1832accd5a4ca2795ace4d05d15c4039be15b62d3b950eff99746a990e3cc10"
dependencies = [
"cfg-if",
"windows-link",
]
[[package]] [[package]]
name = "libm" name = "libm"
version = "0.2.16" version = "0.2.16"
@@ -4002,8 +3991,7 @@ dependencies = [
[[package]] [[package]]
name = "opentelemetry-instrumentation-tower" name = "opentelemetry-instrumentation-tower"
version = "0.19.0" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/open-telemetry/opentelemetry-rust-contrib?rev=6bbbc337aab0bcf10d7799c3e5b5ced75920491a#6bbbc337aab0bcf10d7799c3e5b5ced75920491a"
checksum = "1e7006f3b1853d315462a7237c81eec3d7adfa5b70975a02b19e92d045bc22d7"
dependencies = [ dependencies = [
"axum", "axum",
"http", "http",
@@ -5653,7 +5641,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "969cde0349344dbbf58b5f9badbfb8f806db13969364eb8007c057ef687007d9" checksum = "969cde0349344dbbf58b5f9badbfb8f806db13969364eb8007c057ef687007d9"
dependencies = [ dependencies = [
"annotate-snippets", "annotate-snippets",
"base64 0.22.1", "base64 0.23.1",
"encoding_rs_io", "encoding_rs_io",
"granit-parser", "granit-parser",
"nohash-hasher", "nohash-hasher",
+2 -55
View File
@@ -269,9 +269,6 @@ features = [
[workspace.dependencies.tokio-metrics] [workspace.dependencies.tokio-metrics]
version = "0.5.2" version = "0.5.2"
[workspace.dependencies.libloading]
version = "0.9.0"
[workspace.dependencies.wildmatch] [workspace.dependencies.wildmatch]
version = "2.7.0" version = "2.7.0"
@@ -435,7 +432,8 @@ features = ["reqwest"]
version = "0.33.1" version = "0.33.1"
[workspace.dependencies.opentelemetry-instrumentation-tower] [workspace.dependencies.opentelemetry-instrumentation-tower]
version = "0.19.0" git = "https://github.com/open-telemetry/opentelemetry-rust-contrib"
rev = "6bbbc337aab0bcf10d7799c3e5b5ced75920491a"
default-features = false default-features = false
features = ["axum"] features = ["axum"]
@@ -752,74 +750,23 @@ inherits = "release"
# Developer profile # Developer profile
# #
# To enable hot-reloading:
# 1. Uncomment all of the rustflags here.
# 2. Uncomment crate-type=dylib in src/*/Cargo.toml
#
# opt-level, mir-opt-level, validate-mir are not known to interfere with reloading
# and can be raised if build times are tolerable.
[profile.dev] [profile.dev]
debug = "full" debug = "full"
opt-level = 0 opt-level = 0
panic = "unwind" panic = "unwind"
debug-assertions = true debug-assertions = true
incremental = true incremental = true
#rustflags = [
# '--cfg', 'conduwuit_mods',
# '-Ztime-passes',
# '-Zmir-opt-level=0',
# '-Zvalidate-mir=false',
# '-Ztls-model=global-dynamic',
# '-Cprefer-dynamic=true',
# '-Zstaticlib-prefer-dynamic=true',
# '-Zstaticlib-allow-rdylib-deps=true',
# '-Zpacked-bundled-libs=false',
# '-Zplt=true',
# '-Crpath=true',
# '-Clink-arg=-Wl,--as-needed',
# '-Clink-arg=-Wl,--allow-shlib-undefined',
# '-Clink-arg=-Wl,-z,keep-text-section-prefix',
# '-Clink-arg=-Wl,-z,lazy',
#]
[profile.dev.package.conduwuit_core] [profile.dev.package.conduwuit_core]
inherits = "dev" inherits = "dev"
[profile.dev.package.conduwuit] [profile.dev.package.conduwuit]
inherits = "dev" inherits = "dev"
#rustflags = [
# '--cfg', 'conduwuit_mods',
# '-Ztime-passes',
# '-Zmir-opt-level=0',
# '-Zvalidate-mir=false',
# '-Ztls-model=global-dynamic',
# '-Cprefer-dynamic=true',
# '-Zexport-executable-symbols=true',
# '-Zplt=true',
# '-Crpath=true',
# '-Clink-arg=-Wl,--as-needed',
# '-Clink-arg=-Wl,--allow-shlib-undefined',
# '-Clink-arg=-Wl,--export-dynamic',
# '-Clink-arg=-Wl,-z,lazy',
#]
[profile.dev.package.'*'] [profile.dev.package.'*']
inherits = "dev" inherits = "dev"
debug = 'limited' debug = 'limited'
codegen-units = 1 codegen-units = 1
opt-level = 'z' opt-level = 'z'
#rustflags = [
# '--cfg', 'conduwuit_mods',
# '-Ztls-model=global-dynamic',
# '-Cprefer-dynamic=true',
# '-Zstaticlib-prefer-dynamic=true',
# '-Zstaticlib-allow-rdylib-deps=true',
# '-Zpacked-bundled-libs=true',
# '-Zplt=true',
# '-Clink-arg=-Wl,--as-needed',
# '-Clink-arg=-Wl,-z,lazy',
# '-Clink-arg=-Wl,-z,nodelete',
#]
# primarily used for CI # primarily used for CI
[profile.test] [profile.test]
+1
View File
@@ -0,0 +1 @@
Fixed Prometheus accounting for in-flight requests, federation PDU lag, latency buckets, and thumbnail sizes. Contributed by @eleboucher.
+1
View File
@@ -0,0 +1 @@
A message is now sent to the admin room when a user logs in for the first time through an OIDC provider, if admin room notices are enabled. Contributed by @ginger.
+1 -1
View File
@@ -50,7 +50,7 @@ EOF
# Developer tool versions # Developer tool versions
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall # renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
ENV BINSTALL_VERSION=1.27.0 ENV BINSTALL_VERSION=1.28.0
# renovate: datasource=github-releases depName=psastras/sbom-rs # renovate: datasource=github-releases depName=psastras/sbom-rs
ENV CARGO_SBOM_VERSION=0.9.1 ENV CARGO_SBOM_VERSION=0.9.1
# renovate: datasource=crate depName=lddtree # renovate: datasource=crate depName=lddtree
+1 -1
View File
@@ -18,7 +18,7 @@ RUN --mount=type=cache,target=/etc/apk/cache apk add \
# Developer tool versions # Developer tool versions
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall # renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
ENV BINSTALL_VERSION=1.27.0 ENV BINSTALL_VERSION=1.28.0
# renovate: datasource=github-releases depName=psastras/sbom-rs # renovate: datasource=github-releases depName=psastras/sbom-rs
ENV CARGO_SBOM_VERSION=0.9.1 ENV CARGO_SBOM_VERSION=0.9.1
# renovate: datasource=crate depName=lddtree # renovate: datasource=crate depName=lddtree
-5
View File
@@ -18,10 +18,5 @@
"type": "file", "type": "file",
"name": "testing", "name": "testing",
"label": "Testing" "label": "Testing"
},
{
"type": "file",
"name": "hot_reload",
"label": "Hot Reloading"
} }
] ]
-200
View File
@@ -1,200 +0,0 @@
# Hot Reloading ("Live" Development)
Note that hot reloading has not been refactored in quite a while and is not
guaranteed to work at this time.
### Summary
When developing in debug-builds with the nightly toolchain, Continuwuity is modular
using dynamic libraries and various parts of the application are hot-reloadable
while the server is running: http api handlers, admin commands, services,
database, etc. These are all split up into individual workspace crates as seen
in the `src/` directory. Changes to sourcecode in a crate rebuild that crate and
subsequent crates depending on it. Reloading then occurs for the changed crates.
Release builds still produce static binaries which are unaffected. Rust's
soundness guarantees are in full force. Thus you cannot hot-reload release
binaries.
### Requirements
Currently, this development setup only works on x86_64 and aarch64 Linux glibc.
[musl explicitly does not support hot reloadable libraries, and does not
implement `dlclose`][2]. macOS does not fully support our usage of `RTLD_GLOBAL`
possibly due to some thread-local issues. [This Rust issue][3] may be of
relevance, specifically [this comment][4]. It may be possible to get it working
on only very modern macOS versions such as at least Sonoma, as currently loading
dylibs is supported, but not unloading them in our setup, and the cited comment
mentions an Apple WWDC confirming there have been TLS changes to somewhat make
this possible.
As mentioned above this requires the nightly toolchain. This is due to reliance
on various Cargo.toml features that are only available on nightly, most
specifically `RUSTFLAGS` in Cargo.toml. Some of the implementation could also be
simpler based on other various nightly features. We hope lots of nightly
features start making it out of nightly sooner as there have been dozens of very
helpful features that have been stuck in nightly ("unstable") for at least 5+
years that would make this simpler. We encourage greater community consensus to
move these features into stability.
This currently only works on x86_64/aarch64 Linux with a glibc C library. musl C
library, macOS, and likely other host architectures are not supported (if other
architectures work, feel free to let us know and/or make a PR updating this).
This should work on GNU ld and lld (rust-lld) and gcc/clang, however if you
happen to have linker issues it's recommended to try using `mold` or `gold`
linkers, and please let us know in the [Continuwuity Matrix room][7] the linker
error and what linker solved this issue so we can figure out a solution. Ideally
there should be minimal friction to using this, and in the future a build script
(`build.rs`) may be suitable to making this easier to use if the capabilities
allow us.
### Usage
As of 19 May 2024, the instructions for using this are:
0. Have patience. Don't hesitate to join the [Continuwuity Matrix room][7] to
receive help using this. As indicated by the various rustflags used and some
of the interesting issues linked at the bottom, this is definitely not something
the Rust ecosystem or toolchain is used to doing.
1. Install the nightly toolchain using rustup. You may need to use `rustup
override set nightly` in your local Continuwuity directory, or use `cargo
+nightly` for all actions.
2. Uncomment `cargo-features` at the top level / root Cargo.toml
3. Scroll down to the `# Developer profile` section and uncomment ALL the
rustflags for each dev profile and their respective packages.
4. In each workspace crate's Cargo.toml (everything under `src/*` AND
`deps/rust-rocksdb/Cargo.toml`), uncomment the `dylib` crate type under
`[lib]`.
5. Due to [this rpath issue][5], you must export the `LD_LIBRARY_PATH`
environment variable to your nightly Rust toolchain library directory. If
using rustup (hopefully), use this: `export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/`
6. Start the server. You can use `cargo +nightly run` for this along with the
standard.
7. Make some changes where you need to.
8. In a separate terminal window in the same directory (or using a terminal
multiplexer like tmux), run the *build* Cargo command `cargo +nightly build`.
Cargo should only rebuild what was changed / what's necessary, so it should
not be rebuilding all the crates.
9. In your Continuwuity server terminal, hit/send `CTRL+C` signal. This will tell
Continuwuity to find which libraries need to be reloaded, and reloads them as
necessary.
10. If there were no errors, it will tell you it successfully reloaded `#`
modules, and your changes should now be visible. Repeat 7 - 9 as needed.
To shutdown Continuwuity in this setup, hit/send `CTRL+\`. Normal builds still
shutdown with `CTRL+C` as usual.
Steps 1 - 5 are the initial first-time steps for using this. To remove the hot
reload setup, revert/comment all the Cargo.toml changes.
As mentioned in the requirements section, if you happen to have some linker
issues, try using the `-fuse-ld=` rustflag and specify mold or gold in all the
`rustflags` definitions in the top level Cargo.toml, and please let us know in
the [Continuwuity Matrix room][7] the problem. mold can be installed typically
through your distro, and gold is provided by the binutils package.
It's possible a helper script can be made to do all of this, or most preferably
a specially made build script (build.rs). `cargo watch` support will be
implemented soon which will eliminate the need to manually run `cargo build` all
together.
### Addendum
Conduit was inherited as a single crate without modularity or reloading in its
design. Reasonable partitioning and abstraction allowed a split into several
crates, though many circular dependencies had to be corrected. The resulting
crates now form a directed graph as depicted in figures below. The interfacing
between these crates is still extremely broad which is not mitigable.
Initially [hot_lib_reload][6] was investigated but found appropriate for a
project designed with modularity through limited interfaces, not a large and
complex existing codebase. Instead a bespoke solution built directly on
[libloading][8] satisfied our constraints. This required relatively minimal
modifications and zero maintenance burden compared to what would be required
otherwise. The technical difference lies with relocation processing: we leverage
global bindings (`RTLD_GLOBAL`) in a very intentional way. Most libraries and
off-the-shelf module systems (such as [hot_lib_reload][6]) restrict themselves
to local bindings (`RTLD_LOCAL`). This allows them to release software to
multiple platforms with much greater consistency, but at the cost of burdening
applications to explicitly manage these bindings. In our case with an optional
feature for developers, we shrug any such requirement to enjoy the cost/benefit
on platforms where global relocations are properly cooperative.
To make use of `RTLD_GLOBAL` the application has to be oriented as a directed
acyclic graph. The primary rule is simple and illustrated in the figure below:
**no crate is allowed to call a function or use a variable from a crate below
it.**
![Continuwuity's dynamic library setup diagram - created by Jason
Volk](./assets/libraries.png)
When a symbol is referenced between crates they become bound: **crates cannot be
unloaded until their calling crates are first unloaded.** Thus we start the
reloading process from the crate which has no callers. There is a small problem
though: the first crate is called by the base executable itself! This is solved
by using an `RTLD_LOCAL` binding for just one link between the main executable
and the first crate, freeing the executable from all modules as no global
binding ever occurs between them.
![Continuwuity's reload and load order diagram - created by Jason
Volk](./assets/reload_order.png)
Proper resource management is essential for reliable reloading to occur. This is
a very basic ask in RAII-idiomatic Rust and the exposure to reloading hazards is
remarkably low, generally stemming from poor patterns and practices.
Unfortunately static analysis doesn't enforce reload-safety programmatically
(though it could one day), for now hazards can be avoided by knowing a few basic
do's and dont's:
1. Understand that code is memory. Just like one is forbidden from referencing
free'd memory, one must not transfer control to free'd code. Exposure to this
is primarily from two things:
- Callbacks, which this project makes very little use of.
- Async tasks, which are addressed below.
2. Tie all resources to a scope or object lifetime with greatest possible
symmetry (locality). For our purposes this applies to code resources, which
means async blocks and tokio tasks.
- **Never spawn a task without receiving and storing its JoinHandle**.
- **Always wait on join handles** before leaving a scope or in another cleanup
function called by an owning scope.
3. Know any minor specific quirks documented in code or here:
- Don't use `tokio::spawn`, instead use our `Handle` in `core/server.rs`, which
is reachable in most of the codebase via `services()` or other state. This is
due to some bugs or assumptions made in tokio, as it happens in `unsafe {}`
blocks, which are mitigated by circumventing some thread-local variables. Using
runtime handles is good practice in any case.
The initial implementation PR is available [here][1].
### Interesting related issues/bugs
- [DT_RUNPATH produced in binary with rpath = true is wrong (cargo)][5]
- [Disabling MIR Optimization in Rust Compilation
(cargo)](https://internals.rust-lang.org/t/disabling-mir-optimization-in-rust-compilation/19066/5)
- [Workspace-level metadata
(cargo-deb)](https://github.com/kornelski/cargo-deb/issues/68)
[1]: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/387
[2]: https://wiki.musl-libc.org/functional-differences-from-glibc.html#Unloading-libraries
[3]: https://github.com/rust-lang/rust/issues/28794
[4]: https://github.com/rust-lang/rust/issues/28794#issuecomment-368693049
[5]: https://github.com/rust-lang/cargo/issues/12746
[6]: https://crates.io/crates/hot-lib-reloader/
[7]: https://matrix.to/#/#continuwuity:continuwuity.org?via=continuwuity.org&via=ellis.link&via=explodie.org&via=matrix.org
[8]: https://crates.io/crates/libloading
-7
View File
@@ -37,13 +37,6 @@ It is highly unlikely you will ever need to add a new workspace member, but if
you truly find yourself needing to, we recommend reaching out to us in the you truly find yourself needing to, we recommend reaching out to us in the
Matrix room for discussions about it beforehand. Matrix room for discussions about it beforehand.
The primary inspiration for this design was apart of hot reloadable development,
to support "Continuwuity as a library" where specific parts can simply be
swapped out. There is evidence Conduit wanted to go this route too as `axum` is
technically an optional feature in Conduit, and can be compiled without the
binary or axum library for handling inbound web requests; but it was never
completed or worked.
See the Rust documentation on [Workspaces][workspaces] for general questions and See the Rust documentation on [Workspaces][workspaces] for general questions and
information on Cargo workspaces. information on Cargo workspaces.
+5 -5
View File
@@ -302,7 +302,7 @@
"type": "prometheus", "type": "prometheus",
"uid": "${datasource}" "uid": "${datasource}"
}, },
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\"}[$__rate_interval])))", "expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\",http_route!~\".*/sync\"}[$__rate_interval])))",
"legendFormat": "", "legendFormat": "",
"refId": "A", "refId": "A",
"range": true "range": true
@@ -496,7 +496,7 @@
"type": "prometheus", "type": "prometheus",
"uid": "${datasource}" "uid": "${datasource}"
}, },
"expr": "histogram_quantile(0.5, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\"}[$__rate_interval])))", "expr": "histogram_quantile(0.5, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\",http_route!~\".*/sync\"}[$__rate_interval])))",
"legendFormat": "p50", "legendFormat": "p50",
"refId": "A", "refId": "A",
"range": true "range": true
@@ -506,7 +506,7 @@
"type": "prometheus", "type": "prometheus",
"uid": "${datasource}" "uid": "${datasource}"
}, },
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\"}[$__rate_interval])))", "expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\",http_route!~\".*/sync\"}[$__rate_interval])))",
"legendFormat": "p95", "legendFormat": "p95",
"refId": "B", "refId": "B",
"range": true "range": true
@@ -516,7 +516,7 @@
"type": "prometheus", "type": "prometheus",
"uid": "${datasource}" "uid": "${datasource}"
}, },
"expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\"}[$__rate_interval])))", "expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\",http_route!~\".*/sync\"}[$__rate_interval])))",
"legendFormat": "p99", "legendFormat": "p99",
"refId": "C", "refId": "C",
"range": true "range": true
@@ -1228,7 +1228,7 @@
{ {
"type": "timeseries", "type": "timeseries",
"title": "PDU lag", "title": "PDU lag",
"description": "Time between an accepted PDU's origin_server_ts and its arrival; affected by clock skew", "description": "Time between an accepted PDU's origin_server_ts and its transaction arriving; affected by clock skew",
"id": 21, "id": 21,
"datasource": { "datasource": {
"type": "prometheus", "type": "prometheus",
-4
View File
@@ -36,10 +36,6 @@ List database backups
Send a message to the admin room Send a message to the admin room
## `!admin server reload`
Hot-reload the server
## `!admin server restart` ## `!admin server restart`
Restart the server Restart the server
+131 -104
View File
@@ -16,21 +16,21 @@
} }
}, },
"node_modules/@emnapi/core": { "node_modules/@emnapi/core": {
"version": "1.11.3", "version": "2.0.0-beta.3",
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.3.tgz", "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-2.0.0-beta.3.tgz",
"integrity": "sha512-zLpS5asjEb7lq8jYLq37N6XKaE41DIexlY1rF/z4/tIl3wo13Sqm28fRyfIsKZD+NZ8mM5RoKkpW/rBcuoSZSg==", "integrity": "sha512-KA+gOBtbifRATmUa/Gpf5C2B2EJ0r4brHUT3XSgACeHREcuiObXH56xd+B3fFsEFbUT04VBEe6MuZiCtMp0tQg==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"dependencies": { "dependencies": {
"@emnapi/wasi-threads": "1.2.3", "@emnapi/wasi-threads": "2.2.0",
"tslib": "^2.4.0" "tslib": "^2.4.0"
} }
}, },
"node_modules/@emnapi/runtime": { "node_modules/@emnapi/runtime": {
"version": "1.11.3", "version": "2.0.0-beta.3",
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz", "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-2.0.0-beta.3.tgz",
"integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==", "integrity": "sha512-ayb/PyyLzpwRyFVxeC0uoEHu59QlB1iWGcGsOpXQcaB/Dc+uGfBmNmpCHp3HmTT0t8lSsMmg3j7+tdJW/TlHjQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
@@ -39,9 +39,9 @@
} }
}, },
"node_modules/@emnapi/wasi-threads": { "node_modules/@emnapi/wasi-threads": {
"version": "1.2.3", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.3.tgz", "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-2.2.0.tgz",
"integrity": "sha512-ELEBe8PsLvvJ6QMr0zLt8ffvOHW/dc1m3CEzNMg7aJUv3bMaoDtw2TXyDAwkYBuroxxuHEwhRTLJSe5sya547g==", "integrity": "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
@@ -106,33 +106,36 @@
} }
}, },
"node_modules/@napi-rs/wasm-runtime": { "node_modules/@napi-rs/wasm-runtime": {
"version": "1.1.6", "version": "1.2.7",
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.6.tgz", "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.7.tgz",
"integrity": "sha512-ZLv/JdUfkvOy9eCnnBaGfiO+XimbjebAeO+MRQqD/B+FR1tnRN0tpKSJHRbE8sFfS6aqsXZ67TQjfwfsxULVbg==", "integrity": "sha512-zJccwplOAbgfZju95IUHazLnx9RAPtPN2YGJXI6UbrgeaR9QfPjGrQL6ERkSAtnVCA4Q+83ApGyaX5zdpCaKkQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"dependencies": { "dependencies": {
"@tybys/wasm-util": "^0.10.3" "@tybys/wasm-util": "^0.10.3"
}, },
"engines": {
"node": "^20.19.0 || ^22.13.0 || >=23.5.0"
},
"funding": { "funding": {
"type": "github", "type": "github",
"url": "https://github.com/sponsors/Brooooooklyn" "url": "https://github.com/sponsors/Brooooooklyn"
}, },
"peerDependencies": { "peerDependencies": {
"@emnapi/core": "^1.7.1", "@emnapi/core": "^1.7.1 || 2.0.0-beta.2 || 2.0.0-beta.3",
"@emnapi/runtime": "^1.7.1" "@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2 || 2.0.0-beta.3"
} }
}, },
"node_modules/@rsbuild/core": { "node_modules/@rsbuild/core": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rsbuild/core/-/core-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rsbuild/core/-/core-2.3.3.tgz",
"integrity": "sha512-dv5tL7djb8ex5z4sqnDmUbd5PnGNr/CXuFfiMD4RkUsF1JEZZkGH8lc+QW4fqYQIHM7RTvcMUakgvwVU/O9WMw==", "integrity": "sha512-IdbBXZrIY16RxnQduXRrsRBQtJ/X7JkYESrk6D46WA918wrckYTBxE09vHvDxR+3JoCLE02vOm2NPBNxqaUw5A==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@rspack/core": "~2.3.1", "@rspack/core": "~2.3.3",
"@swc/helpers": "^0.5.23" "@swc/helpers": "^0.5.24"
}, },
"bin": { "bin": {
"rsbuild": "bin/rsbuild.js" "rsbuild": "bin/rsbuild.js"
@@ -169,32 +172,32 @@
} }
}, },
"node_modules/@rspack/binding": { "node_modules/@rspack/binding": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding/-/binding-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding/-/binding-2.3.3.tgz",
"integrity": "sha512-pfCJGBFNK2tnNnoDP6ZoTbOjxbKr1U2eGFDJ8bIuZQai4FBNhWQlKFmNup+X5K935XYRulZBomIBAL6GL6W2YQ==", "integrity": "sha512-wwF++36a3rqYi0G9zj+rUavn/GIMzbzXehelGS1jkYeKPHyPXrVYwRHqwEKNKMD9z+FdW4YJKQcfFkPlHEiwUg==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"optionalDependencies": { "optionalDependencies": {
"@rspack/binding-darwin-arm64": "2.3.1", "@rspack/binding-darwin-arm64": "2.3.3",
"@rspack/binding-darwin-x64": "2.3.1", "@rspack/binding-darwin-x64": "2.3.3",
"@rspack/binding-linux-arm64-gnu": "2.3.1", "@rspack/binding-linux-arm64-gnu": "2.3.3",
"@rspack/binding-linux-arm64-musl": "2.3.1", "@rspack/binding-linux-arm64-musl": "2.3.3",
"@rspack/binding-linux-ppc64-gnu": "2.3.1", "@rspack/binding-linux-ppc64-gnu": "2.3.3",
"@rspack/binding-linux-riscv64-gnu": "2.3.1", "@rspack/binding-linux-riscv64-gnu": "2.3.3",
"@rspack/binding-linux-riscv64-musl": "2.3.1", "@rspack/binding-linux-riscv64-musl": "2.3.3",
"@rspack/binding-linux-s390x-gnu": "2.3.1", "@rspack/binding-linux-s390x-gnu": "2.3.3",
"@rspack/binding-linux-x64-gnu": "2.3.1", "@rspack/binding-linux-x64-gnu": "2.3.3",
"@rspack/binding-linux-x64-musl": "2.3.1", "@rspack/binding-linux-x64-musl": "2.3.3",
"@rspack/binding-wasm32-wasi": "2.3.1", "@rspack/binding-wasm32-wasi": "2.3.3",
"@rspack/binding-win32-arm64-msvc": "2.3.1", "@rspack/binding-win32-arm64-msvc": "2.3.3",
"@rspack/binding-win32-ia32-msvc": "2.3.1", "@rspack/binding-win32-ia32-msvc": "2.3.3",
"@rspack/binding-win32-x64-msvc": "2.3.1" "@rspack/binding-win32-x64-msvc": "2.3.3"
} }
}, },
"node_modules/@rspack/binding-darwin-arm64": { "node_modules/@rspack/binding-darwin-arm64": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-arm64/-/binding-darwin-arm64-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-darwin-arm64/-/binding-darwin-arm64-2.3.3.tgz",
"integrity": "sha512-koLyL2r8PUcLD0StjuZ/n5XM6GJ0C8dzJN0IuIV9d7nQcibJxwjjSAWEPGVz6bm8WuzypvuVKNoa1+GGAHeMQA==", "integrity": "sha512-G9WcBOP/6ZWeqTM/G0/rkJRY4DWmYQvk2untzcpj92uO12tqjZ9BSMgtBFvwElwagfQBkX8PPutkAZgtnlAoWA==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -206,9 +209,9 @@
] ]
}, },
"node_modules/@rspack/binding-darwin-x64": { "node_modules/@rspack/binding-darwin-x64": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-x64/-/binding-darwin-x64-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-darwin-x64/-/binding-darwin-x64-2.3.3.tgz",
"integrity": "sha512-YK39JLiu1YC6+3BMxkP7e848pHD7e2T/0OSNogDi7whfiZNg95wa9Ncd7I5ppAf0nhmV+FNew/sCBIFp5h67Jw==", "integrity": "sha512-6agI5XDoihay+84vzZgIwwpQQ3xBWbe2HTWBRc0n42LzynIj9h7Qv8CJzf1gSDV1Ts0jzDgAJCYUFJ6Ya5F6MA==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -220,13 +223,16 @@
] ]
}, },
"node_modules/@rspack/binding-linux-arm64-gnu": { "node_modules/@rspack/binding-linux-arm64-gnu": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-2.3.3.tgz",
"integrity": "sha512-Q+RCA/KM2tn6m6R5U4lktXDs5cCRm3SyleQk86iqqUFX7wKzVRUvr5BTsreg6K9of3gpYmQ6+g1PGT5cwo0rLA==", "integrity": "sha512-VdjK1mDq+GBexd041lmWBFmAvcWIZy7kepTJbJgxLeHYYOnI3KmBG15kemhlK0pBySa+bePX7p2w8uYtl1HsCA==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
"dev": true, "dev": true,
"libc": [
"glibc"
],
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"os": [ "os": [
@@ -234,13 +240,16 @@
] ]
}, },
"node_modules/@rspack/binding-linux-arm64-musl": { "node_modules/@rspack/binding-linux-arm64-musl": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-musl/-/binding-linux-arm64-musl-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-musl/-/binding-linux-arm64-musl-2.3.3.tgz",
"integrity": "sha512-He+muVDON1fohGtdYamh3zHVwf6/E6fZu/+iEAkxjclE0P94bsCfYVcZW/a4/l1tJ2zvLZtB4jD7Qr6r4vG/WA==", "integrity": "sha512-xF4Wy4XwGjC3m13tFm1q9p9Qpm31qrk6f5zEMPZC31UVabb+2jrgTI1pfZ8IRuo9x/Qw9s+Zq3hyDbtJvvD8Pg==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
"dev": true, "dev": true,
"libc": [
"musl"
],
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"os": [ "os": [
@@ -248,13 +257,16 @@
] ]
}, },
"node_modules/@rspack/binding-linux-ppc64-gnu": { "node_modules/@rspack/binding-linux-ppc64-gnu": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-2.3.3.tgz",
"integrity": "sha512-blIZUgyPt4FcSHkZL6sJ2xbzc7ACgDeU49An4mXLSebwdgnlhTzxeSFnh2VeJDlGza8CUaZYB/zS/6oZ2kCDcw==", "integrity": "sha512-jVmn+LpF44D4FdZyT91rlT/tPMdHIfPfQTgVzwPB5nDICp4b57SFjVBApuAPIxnLT1pKLkv/LIcdvGSdAeX12w==",
"cpu": [ "cpu": [
"ppc64" "ppc64"
], ],
"dev": true, "dev": true,
"libc": [
"glibc"
],
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"os": [ "os": [
@@ -262,13 +274,16 @@
] ]
}, },
"node_modules/@rspack/binding-linux-riscv64-gnu": { "node_modules/@rspack/binding-linux-riscv64-gnu": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-gnu/-/binding-linux-riscv64-gnu-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-gnu/-/binding-linux-riscv64-gnu-2.3.3.tgz",
"integrity": "sha512-3FtW2DUFmXxhBORUA3zSc+ot4d6R/1/U6z/48TDN4jeIYDUG9VqYBF6LUohX4vBY6IP0DCyXb2N9WayD/9QXoA==", "integrity": "sha512-JcQJm8M634jkbG6zJ3TfziKYsCINEAh3FwKuxLljvBgGDEupBxPuB0n2bXBIUeI8P9C33B45IYX6BwWYXll/zw==",
"cpu": [ "cpu": [
"riscv64" "riscv64"
], ],
"dev": true, "dev": true,
"libc": [
"glibc"
],
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"os": [ "os": [
@@ -276,13 +291,16 @@
] ]
}, },
"node_modules/@rspack/binding-linux-riscv64-musl": { "node_modules/@rspack/binding-linux-riscv64-musl": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-musl/-/binding-linux-riscv64-musl-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-musl/-/binding-linux-riscv64-musl-2.3.3.tgz",
"integrity": "sha512-+5qNgdNdXzp/K8f8BjgJ3m7tcbBKPENN7WPDfBcSHvWb5GF4+o/pbrX26c0+LEugo0bYUOAoitBNd94AwcNvpA==", "integrity": "sha512-YMIOS7rFvCDnpeyxoVEVbM7U/TwcC2VDtN3Oiq9BenRsNTEvk0imINhuVRFanh15+wkiQHk9h0b+pzcggYLAsA==",
"cpu": [ "cpu": [
"riscv64" "riscv64"
], ],
"dev": true, "dev": true,
"libc": [
"musl"
],
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"os": [ "os": [
@@ -290,13 +308,16 @@
] ]
}, },
"node_modules/@rspack/binding-linux-s390x-gnu": { "node_modules/@rspack/binding-linux-s390x-gnu": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-2.3.3.tgz",
"integrity": "sha512-yNcg/y1+MV0wZ984CVU4d1HAYYwMcDPXoQO0xynU+K5YuBxPWALHOxuRRCKCcykBdL1GIEshAIewEFrsW/cmJg==", "integrity": "sha512-tHGtIG6GGHsk2KvSleQp/BrVqiGdjDsLJuMKR7hE7W1uJW6WDJ+a+Z23Rk5kHXh5BjeFLjXxcufGuokvmLmTag==",
"cpu": [ "cpu": [
"s390x" "s390x"
], ],
"dev": true, "dev": true,
"libc": [
"glibc"
],
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"os": [ "os": [
@@ -304,13 +325,16 @@
] ]
}, },
"node_modules/@rspack/binding-linux-x64-gnu": { "node_modules/@rspack/binding-linux-x64-gnu": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-gnu/-/binding-linux-x64-gnu-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-gnu/-/binding-linux-x64-gnu-2.3.3.tgz",
"integrity": "sha512-ffclKBuH8wwimOBd6xGUxrBfVKKY5Ow4E7OFdHZeg4xffm2O8auGszmOgvFu1eoDoOYHaVJn+cEV6UD0KwZk8A==", "integrity": "sha512-spe8SjywfO+dD7Sk+vIpPaOXf56wstrgeuztfJdiI9zTeQmf/lhdaNUUSUAXlGIaLjrN/PhV8i5kbQ7VaAkenw==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
"dev": true, "dev": true,
"libc": [
"glibc"
],
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"os": [ "os": [
@@ -318,13 +342,16 @@
] ]
}, },
"node_modules/@rspack/binding-linux-x64-musl": { "node_modules/@rspack/binding-linux-x64-musl": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-musl/-/binding-linux-x64-musl-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-musl/-/binding-linux-x64-musl-2.3.3.tgz",
"integrity": "sha512-qcDwwuyxR7TMtrW+r5Y9RIW25boXd1Ip/9jz04jhdq/OiU/Am7rCP2X90CH8sWdzovIF9UNmsGjY4KklR0F2Mg==", "integrity": "sha512-4E4OJodrmsS52zkSAWShG/F07etr0OG4oSrIN+/2BBgc0qR2wwu2T+rAs308IL3lbywlS+J+cynrRcsSFMD+Kg==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
"dev": true, "dev": true,
"libc": [
"musl"
],
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"os": [ "os": [
@@ -332,9 +359,9 @@
] ]
}, },
"node_modules/@rspack/binding-wasm32-wasi": { "node_modules/@rspack/binding-wasm32-wasi": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-wasm32-wasi/-/binding-wasm32-wasi-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-wasm32-wasi/-/binding-wasm32-wasi-2.3.3.tgz",
"integrity": "sha512-3dr6zjFaCK3A920ftCriSJkiRhEfhHtat7LtBdj6g0mcV5Rt+iealmli0vjeAvD0UdpE1u8EKWlfw82JLgFLSQ==", "integrity": "sha512-AhlsPjW31TGP8N+J7OmbCPaamARUl+OQNiT3xo0PL5Dz5oMm+bEfYLostpehKyy8MNDrmJcY97M9pDb5MDMA0w==",
"cpu": [ "cpu": [
"wasm32" "wasm32"
], ],
@@ -342,15 +369,15 @@
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
"dependencies": { "dependencies": {
"@emnapi/core": "1.11.3", "@emnapi/core": "2.0.0-beta.3",
"@emnapi/runtime": "1.11.3", "@emnapi/runtime": "2.0.0-beta.3",
"@napi-rs/wasm-runtime": "1.1.6" "@napi-rs/wasm-runtime": "1.2.7"
} }
}, },
"node_modules/@rspack/binding-win32-arm64-msvc": { "node_modules/@rspack/binding-win32-arm64-msvc": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-2.3.3.tgz",
"integrity": "sha512-AZbuLPylt1xvWssN93AsirbYs3WgfcrA8tMsqHmVJIHahLu9E+JPKZ3Gmsw6IYEZk3EfnV3ujQzeQ1/VfF0Vsw==", "integrity": "sha512-Zqbj7GBPtkJ8GlUKAjFgvmOxKkQwjfS3XfjwGBcmoIAUb4IxUsmMqvi+gfKrvI45SjYVFZaJnTpOJw6GL79K+Q==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -362,9 +389,9 @@
] ]
}, },
"node_modules/@rspack/binding-win32-ia32-msvc": { "node_modules/@rspack/binding-win32-ia32-msvc": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-2.3.3.tgz",
"integrity": "sha512-R5NVU68TePZcgRdYUzrQX9YFNxmcyXZEPwaPv40AAgsqNyacG3iRaYVmV79jt3rWYfa0QJaqvRLUchDe2SZ6zQ==", "integrity": "sha512-sJJmbrdzH6kI48mCsUu5a2+BzEktLmHrHUmWGkAPAi0zhi4anA7sOdS1+uERbkkd/XAzs0bdn3JXyT2djY+3IA==",
"cpu": [ "cpu": [
"ia32" "ia32"
], ],
@@ -376,9 +403,9 @@
] ]
}, },
"node_modules/@rspack/binding-win32-x64-msvc": { "node_modules/@rspack/binding-win32-x64-msvc": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-x64-msvc/-/binding-win32-x64-msvc-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/binding-win32-x64-msvc/-/binding-win32-x64-msvc-2.3.3.tgz",
"integrity": "sha512-5T9DYjNPQpLbrNXjCssGd2B6xMQPlc3LxVOKHGUA1O0GV+88vBkTXAcryJ+Fo+yVEMPCzp4VvwBMGAVDpCjcSA==", "integrity": "sha512-1r3wxV1pBNykqpbEbZWqcrZd13PKLq0e7Ku6qv8IGKKeftuf3RUxTkeM5AzppGMGEIA9sw8mRdN7NvEXxqLLxw==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -390,13 +417,13 @@
] ]
}, },
"node_modules/@rspack/core": { "node_modules/@rspack/core": {
"version": "2.3.1", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/@rspack/core/-/core-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@rspack/core/-/core-2.3.3.tgz",
"integrity": "sha512-9BWfaiEJLgLK9U53Q4WVruBZ19Mu/XWHXHEu0UFla4lUtH8Z+/ET2m044tiqbtyIgqQyG58fMrxHeVIAiXMXHg==", "integrity": "sha512-stAYr0SXf+ZFXFsWTv+Ljxoj/nQs2p7gX9V1kBwlO2IXlRAAhabLONYibT3ZeEGybx3kowrs7uJkcOQsuHgghw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@rspack/binding": "2.3.1" "@rspack/binding": "2.3.3"
}, },
"engines": { "engines": {
"node": "^20.19.0 || >=22.12.0" "node": "^20.19.0 || >=22.12.0"
@@ -431,17 +458,17 @@
} }
}, },
"node_modules/@rspress/core": { "node_modules/@rspress/core": {
"version": "2.1.3", "version": "2.1.4",
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.3.tgz", "resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.4.tgz",
"integrity": "sha512-qKa5c7zHO8cmhxkReURd3dN/ZRfHYnEztdIQ9hMuolaNzhSYo2A36XErUvLvbMf2EUM2AxfPYRQv+4Crfeq6pw==", "integrity": "sha512-7OmP7ABDgQLSpVfpBHfpjqu4H3PGBGMyhLxF1crPQ48Q6MIWAVu77nw7cONn8AZa9GoVq0N/DoE3GEtgZzlu6w==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@mdx-js/mdx": "^3.1.1", "@mdx-js/mdx": "^3.1.1",
"@mdx-js/react": "^3.1.1", "@mdx-js/react": "^3.1.1",
"@rsbuild/core": "^2.2.14", "@rsbuild/core": "^2.3.3",
"@rsbuild/plugin-react": "~2.1.1", "@rsbuild/plugin-react": "~2.1.1",
"@rspress/shared": "2.1.3", "@rspress/shared": "2.1.4",
"@shikijs/rehype": "^4.2.0", "@shikijs/rehype": "^4.2.0",
"@shikijs/transformers": "^4.2.0", "@shikijs/transformers": "^4.2.0",
"@types/mdast": "^4.0.4", "@types/mdast": "^4.0.4",
@@ -485,9 +512,9 @@
} }
}, },
"node_modules/@rspress/plugin-client-redirects": { "node_modules/@rspress/plugin-client-redirects": {
"version": "2.1.3", "version": "2.1.4",
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.1.3.tgz", "resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.1.4.tgz",
"integrity": "sha512-iEqJ8qEFuUxGKRVaS/WMyFi8FiJlogdcEHbGK/UjY8+8Hg8r8aSv4YihmNh3Ev/uIW21hrC8aXMEgVo0H51Q+g==", "integrity": "sha512-6/g+Mr8lslqiFzlMBouex8TLm6PlQK6cmZ71Yfv82+Uxcrb+LaFAFiPbq2G7gToXBQUoECM4D/7nSLAfeOhnEQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
@@ -498,9 +525,9 @@
} }
}, },
"node_modules/@rspress/plugin-sitemap": { "node_modules/@rspress/plugin-sitemap": {
"version": "2.1.3", "version": "2.1.4",
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.3.tgz", "resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.4.tgz",
"integrity": "sha512-Fqo7/4PfQK1ecHUFoUDMrR/E+Hcu+kIohxSs8QabflMy3dqk+M3ZqzJDOHpVYB+HLLGwKiqkPLT4BK+W93clkw==", "integrity": "sha512-TObDTXgBKFAHEWEth47aehQSYtFfpIkqM4w14a0hUbPLkbu2AZ2cKnMzFTKK+W6I/3LN54scvfGYTL5CPQsDXw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
@@ -511,13 +538,13 @@
} }
}, },
"node_modules/@rspress/shared": { "node_modules/@rspress/shared": {
"version": "2.1.3", "version": "2.1.4",
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.3.tgz", "resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.4.tgz",
"integrity": "sha512-VwJ7kgsTWVqHzSXQVHIUCsdMparmq9b/IDmTa3a6jMPl1zmm5Qg9M0eP4j8JXWoIS9n19XtCkQcZmMTFOPRy3A==", "integrity": "sha512-SuQyVKn9xcQwkzfl+4bPBzX10gxbhCs9UupqSoPtxvyr9pMgSbXnlo3gxTPZXLzk5HUqZZ6tlIju25PVCEtYWA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@rsbuild/core": "^2.2.14", "@rsbuild/core": "^2.3.3",
"@shikijs/rehype": "^4.2.0", "@shikijs/rehype": "^4.2.0",
"@types/react": "^19.3.0", "@types/react": "^19.3.0",
"mdast-util-mdx-jsx": "^3.2.1", "mdast-util-mdx-jsx": "^3.2.1",
@@ -672,9 +699,9 @@
"license": "Apache-2.0" "license": "Apache-2.0"
}, },
"node_modules/@tybys/wasm-util": { "node_modules/@tybys/wasm-util": {
"version": "0.10.4", "version": "0.10.5",
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz", "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.5.tgz",
"integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==", "integrity": "sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"optional": true, "optional": true,
-3
View File
@@ -34,9 +34,6 @@ pub(crate) use crate::{context::Context, utils::get_room_info};
pub(crate) const PAGE_SIZE: usize = 100; pub(crate) const PAGE_SIZE: usize = 100;
conduwuit::mod_ctor! {}
conduwuit::mod_dtor! {}
pub use crate::admin::AdminCommand; pub use crate::admin::AdminCommand;
/// Install the admin command processor /// Install the admin command processor
-8
View File
@@ -110,14 +110,6 @@ impl crate::Context<'_> {
self.write_str("Notice was sent to #admins").await self.write_str("Notice was sent to #admins").await
} }
pub(super) async fn reload_mods(&self) -> Result {
self.bail_restricted()?;
self.services.server.reload()?;
self.write_str("Reloading server...").await
}
#[cfg(unix)] #[cfg(unix)]
pub(super) async fn restart(&self, force: bool) -> Result { pub(super) async fn restart(&self, force: bool) -> Result {
use conduwuit::utils::sys::current_exe_deleted; use conduwuit::utils::sys::current_exe_deleted;
-4
View File
@@ -39,10 +39,6 @@ pub enum ServerCommand {
message: Vec<String>, message: Vec<String>,
}, },
/// Hot-reload the server
#[command(name = "reload", alias = "reload-mods")]
ReloadMods,
#[cfg(unix)] #[cfg(unix)]
/// Restart the server /// Restart the server
Restart { Restart {
-3
View File
@@ -16,6 +16,3 @@ pub mod client_ip;
pub mod admin; pub mod admin;
pub(crate) use self::router::{Ruma, RumaResponse, State}; pub(crate) use self::router::{Ruma, RumaResponse, State};
conduwuit::mod_ctor! {}
conduwuit::mod_dtor! {}
+2 -1
View File
@@ -332,6 +332,7 @@ async fn handle_room(
room_id: OwnedRoomId, room_id: OwnedRoomId,
pdus: impl Iterator<Item = Pdu> + Send, pdus: impl Iterator<Item = Pdu> + Send,
) -> std::result::Result<Vec<(OwnedEventId, Result)>, TransactionError> { ) -> std::result::Result<Vec<(OwnedEventId, Result)>, TransactionError> {
let arrived = millis_since_unix_epoch();
let _room_lock = services let _room_lock = services
.rooms .rooms
.event_handler .event_handler
@@ -392,7 +393,7 @@ async fn handle_room(
.federation_incoming_pdu_duration .federation_incoming_pdu_duration
.record(start.elapsed().as_secs_f64(), std::slice::from_ref(&outcome)); .record(start.elapsed().as_secs_f64(), std::slice::from_ref(&outcome));
if let (Ok(()), Some(ts)) = (&result, origin_server_ts) { if let (Ok(()), Some(ts)) = (&result, origin_server_ts) {
let lag = millis_since_unix_epoch().saturating_sub(ts); let lag = arrived.saturating_sub(ts);
instruments instruments
.federation_incoming_pdu_lag .federation_incoming_pdu_lag
.record(Duration::from_millis(lag).as_secs_f64(), &[]); .record(Duration::from_millis(lag).as_secs_f64(), &[]);
-5
View File
@@ -20,9 +20,6 @@ crate-type = [
brotli_compression = [ brotli_compression = [
"reqwest/brotli", "reqwest/brotli",
] ]
conduwuit_mods = [
"dep:libloading"
]
gzip_compression = [ gzip_compression = [
"reqwest/gzip", "reqwest/gzip",
] ]
@@ -85,8 +82,6 @@ http-body-util.workspace = true
http.workspace = true http.workspace = true
ipaddress.workspace = true ipaddress.workspace = true
libc.workspace = true libc.workspace = true
libloading.workspace = true
libloading.optional = true
lettre.workspace = true lettre.workspace = true
num-traits.workspace = true num-traits.workspace = true
rand.workspace = true rand.workspace = true
+142 -85
View File
@@ -1,8 +1,6 @@
use std::{ use std::{
cell::{Cell, RefCell},
ops::Deref, ops::Deref,
ptr, ptr::NonNull,
ptr::null_mut,
sync::{ sync::{
Arc, Arc,
atomic::{AtomicPtr, Ordering}, atomic::{AtomicPtr, Ordering},
@@ -10,119 +8,178 @@ use std::{
}; };
use super::Config; use super::Config;
use crate::Result; use crate::{Result, SyncMutex};
/// The configuration manager is an indirection to reload the configuration for /// The configuration manager is an indirection to reload the configuration for
/// the server while it is running. In order to not burden or clutter the many /// the server while it is running. In order to not burden or clutter the many
/// callsites which query for configuration items, this object implements Deref /// callsites which query for configuration items, this object implements Deref
/// for the actively loaded configuration. /// for the actively loaded configuration.
///
/// Every installed `Arc<Config>` is kept at a stable heap address in `retired`
/// for the entire lifetime of `Manager` (intentionally retaining prior configs
/// across the rare, admin-triggered reloads until shutdown). Because
/// `Deref::deref(&self)` ties the returned `&Arc<Config>` lifetime to `&self`,
/// readers can perform a single `Acquire` load with no locking, no TLS, and no
/// risk of dangling or aliasing UB across reloads.
pub struct Manager { pub struct Manager {
active: AtomicPtr<Config>, active: AtomicPtr<Arc<Config>>,
/// Append-only owner of every `Box<Arc<Config>>` ever published to
/// `active` (including the currently active config). Entries are only
/// freed when `Manager` itself is dropped (`&mut self`), guaranteeing that
/// any `&Arc<Config>` returned by `Deref::deref` remains valid and
/// immutable for the lifetime of `self`.
retired: SyncMutex<Vec<PinnedConfig>>,
} }
thread_local! { /// Heap-pinned `Arc<Config>` stored as a raw `NonNull` rather than `Box` so
static INDEX: Cell<usize> = 0.into(); /// moving it (e.g., when `Vec` reallocates) never retags or invalidates raw
static HANDLE: RefCell<Handles> = const { /// pointers previously published to `Manager::active`.
RefCell::new([const { None }; HISTORY]) struct PinnedConfig(NonNull<Arc<Config>>);
};
// SAFETY: `Arc<Config>` is `Send + Sync`, and `PinnedConfig` uniquely owns the
// `Box<Arc<Config>>` allocation until it is dropped in `Manager::drop`.
unsafe impl Send for PinnedConfig {}
impl PinnedConfig {
fn new(config: Config) -> Self {
let ptr = Box::into_raw(Box::new(Arc::new(config)));
Self(NonNull::new(ptr).expect("Box::into_raw returned null"))
}
#[inline]
const fn as_ptr(&self) -> *mut Arc<Config> { self.0.as_ptr() }
} }
type Handle = Option<Arc<Config>>; impl Drop for PinnedConfig {
type Handles = [Handle; HISTORY]; fn drop(&mut self) {
// SAFETY: `self.0` was created via `Box::into_raw` in
const HISTORY: usize = 8; // `PinnedConfig::new` and is only dropped when `Manager` itself is
// dropped (`&mut self`), after all borrows derived from `Deref::deref`
// have ended.
unsafe {
drop(Box::from_raw(self.0.as_ptr()));
}
}
}
impl Manager { impl Manager {
pub(crate) fn new(config: Config) -> Self { pub(crate) fn new(config: Config) -> Self {
let config = Arc::new(config); let pinned = PinnedConfig::new(config);
let ptr = pinned.as_ptr();
Self { Self {
active: AtomicPtr::new(Arc::into_raw(config).cast_mut()), active: AtomicPtr::new(ptr),
retired: SyncMutex::new(vec![pinned]),
} }
} }
/// Update the active configuration, returning prior configuration. /// Update the active configuration, returning prior configuration.
#[tracing::instrument(skip_all, level = "info")] #[tracing::instrument(skip_all, level = "info")]
pub fn update(&self, config: Config) -> Result<Arc<Config>> { pub fn update(&self, config: Config) -> Result<Arc<Config>> {
let config = Arc::new(config); let pinned = PinnedConfig::new(config);
let new = Arc::into_raw(config); let new_ptr = pinned.as_ptr();
let old = self.active.swap(new.cast_mut(), Ordering::AcqRel);
// SAFETY: The old active pointer was set using an Arc::into_raw(). let mut retired = self.retired.lock();
// We're obliged to reconstitute that into Arc otherwise it will leak. // Push before publishing to `active` so ownership is recorded even if
Ok(unsafe { Arc::from_raw(old) }) // `Vec::push` were to unwind.
} retired.push(pinned);
fn load(&self, handle: &mut [Option<Arc<Config>>]) -> &'static Arc<Config> { // `Release` publishes the initialized `Box<Arc<Config>>` to readers
let config = self.active.load(Ordering::Acquire); // performing `Acquire` loads in `Deref::deref`.
let old_ptr = self.active.swap(new_ptr, Ordering::AcqRel);
// Branch taken after config reload or first access by this thread. // SAFETY: `old_ptr` points to a `PinnedConfig` still owned by `retired`
if handle[INDEX.get()] // and cannot be freed until `Manager` is dropped.
.as_ref() let old = unsafe { Arc::clone(&*old_ptr) };
.is_none_or(|handle| !ptr::eq(config, Arc::as_ptr(handle)))
{
INDEX.set(INDEX.get().wrapping_add(1).wrapping_rem(HISTORY));
return load_miss(handle, INDEX.get(), config);
}
let config: &Arc<Config> = handle[INDEX.get()] Ok(old)
.as_ref()
.expect("handle was already cached for this thread");
// SAFETY: The caller should not hold multiple references at a time
// directly into Config, as a subsequent reference might invalidate
// the thread's cache causing another reference to dangle.
//
// This is a highly unusual pattern as most config values are copied by
// value or used immediately without running overlap with another
// value. Even if it does actually occur somewhere, the window of
// danger is limited to the config being reloaded while the reference
// is held and another access is made by the same thread into a
// different config value. This is mitigated by creating a buffer
// of old configs rather than discarding at the earliest opportunity;
// the odds of this scenario are thus astronomical.
unsafe { std::mem::transmute(config) }
}
}
impl Drop for Manager {
fn drop(&mut self) {
let config = self.active.swap(null_mut(), Ordering::AcqRel);
// SAFETY: The active pointer was set using an Arc::into_raw(). We're
// obliged to reconstitute that into Arc otherwise it will leak.
unsafe { Arc::from_raw(config) };
} }
} }
impl Deref for Manager { impl Deref for Manager {
type Target = Arc<Config>; type Target = Arc<Config>;
fn deref(&self) -> &Self::Target { HANDLE.with_borrow_mut(|handle| self.load(handle)) } #[inline]
fn deref(&self) -> &Self::Target {
let ptr = self.active.load(Ordering::Acquire);
// SAFETY: `ptr` was initialized in `Manager::new` or published via
// `Ordering::AcqRel` in `Manager::update` and points to a
// `PinnedConfig` in `self.retired`. Entries in `self.retired` are never
// removed or mutated until `Manager` is dropped (`&mut self`), so the
// returned `&'self Arc<Config>` remains valid and immutable for the
// entire borrow of `self`.
unsafe { &*ptr }
}
} }
#[tracing::instrument( #[cfg(test)]
name = "miss", mod tests {
level = "trace", use std::thread;
skip_all,
fields(%index, ?config)
)]
#[allow(clippy::transmute_ptr_to_ptr)]
fn load_miss(
handle: &mut [Option<Arc<Config>>],
index: usize,
config: *const Config,
) -> &'static Arc<Config> {
// SAFETY: The active pointer was set prior and always remains valid. We're
// reconstituting the Arc here but as a new reference, so the count is
// incremented. This instance will be cached in the thread-local.
let config = unsafe {
Arc::increment_strong_count(config);
Arc::from_raw(config)
};
// SAFETY: See the note on the transmute above. The caller should not hold use super::*;
// more than one reference at a time directly into Config, as the second
// access might invalidate the thread's cache, dangling the reference to fn test_config(server_name: &str) -> Config {
// the first. use figment::{
unsafe { std::mem::transmute(handle[index].insert(config)) } Figment,
providers::{Format, Toml},
};
let raw = format!("server_name = \"{server_name}\"\ndatabase_path = \"/tmp\"\n");
Figment::new()
.merge(Toml::string(&raw))
.extract()
.expect("valid test config")
}
#[test]
fn deref_survives_many_reloads() {
let manager = Manager::new(test_config("initial.example"));
let first: &Arc<Config> = &manager;
let first_name: &str = first.server_name.as_str();
for i in 0..32 {
let prev = manager
.update(test_config(&format!("reload-{i}.example")))
.expect("update succeeds");
if i == 0 {
assert_eq!(prev.server_name.as_str(), "initial.example");
}
}
// Original reference remains valid and unchanged after > HISTORY
// reloads.
assert_eq!(first_name, "initial.example");
assert_eq!(manager.server_name.as_str(), "reload-31.example");
}
#[test]
fn concurrent_reads_and_updates() {
let manager = Manager::new(test_config("start.example"));
thread::scope(|s| {
for _ in 0..4 {
s.spawn(|| {
for _ in 0..200 {
let cfg: &Arc<Config> = &manager;
assert!(cfg.server_name.as_str().ends_with(".example"));
}
});
}
s.spawn(|| {
for i in 0..32 {
let _ = manager
.update(test_config(&format!("iter-{i}.example")))
.expect("update succeeds");
}
});
});
}
#[test]
fn reference_outlives_scoped_thread() {
let manager = Manager::new(test_config("scoped.example"));
let cfg_ref: &Arc<Config> = thread::scope(|s| s.spawn(|| &*manager).join().unwrap());
assert_eq!(cfg_ref.server_name.as_str(), "scoped.example");
}
} }
+20 -4
View File
@@ -45,6 +45,14 @@ impl Instruments {
.with_boundaries(duration_buckets()) .with_boundaries(duration_buckets())
.build() .build()
}; };
let long_duration = |name: &'static str, description: &'static str| {
meter
.f64_histogram(name)
.with_description(description)
.with_unit("s")
.with_boundaries(long_duration_buckets())
.build()
};
let size = |name: &'static str, description: &'static str| { let size = |name: &'static str, description: &'static str| {
meter meter
.u64_histogram(name) .u64_histogram(name)
@@ -55,11 +63,11 @@ impl Instruments {
}; };
Self { Self {
federation_outgoing_request_duration: duration( federation_outgoing_request_duration: long_duration(
"continuwuity.federation.outgoing.request.duration", "continuwuity.federation.outgoing.request.duration",
"Duration of outgoing federation requests", "Duration of outgoing federation requests",
), ),
federation_incoming_transaction_duration: duration( federation_incoming_transaction_duration: long_duration(
"continuwuity.federation.incoming.transaction.duration", "continuwuity.federation.incoming.transaction.duration",
"Time taken to process incoming federation transactions", "Time taken to process incoming federation transactions",
), ),
@@ -75,11 +83,13 @@ impl Instruments {
federation_incoming_pdu_lag: meter federation_incoming_pdu_lag: meter
.f64_histogram("continuwuity.federation.incoming.pdu.lag") .f64_histogram("continuwuity.federation.incoming.pdu.lag")
.with_description( .with_description(
"Time between an accepted incoming PDU's origin_server_ts and its arrival", "Time between an accepted incoming PDU's origin_server_ts and its \
transaction arriving",
) )
.with_unit("s") .with_unit("s")
.with_boundaries(vec![ .with_boundaries(vec![
0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0, 30.0, 60.0, 300.0, 900.0, 3600.0, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0, 30.0, 60.0, 300.0, 900.0, 3600.0,
21600.0, 86400.0,
]) ])
.build(), .build(),
federation_incoming_edus: meter federation_incoming_edus: meter
@@ -92,7 +102,7 @@ impl Instruments {
"Time taken to handle an incoming federation EDU", "Time taken to handle an incoming federation EDU",
), ),
sender_transaction_duration: duration( sender_transaction_duration: long_duration(
"continuwuity.sender.transaction.duration", "continuwuity.sender.transaction.duration",
"Duration of outgoing transactions by destination type and outcome", "Duration of outgoing transactions by destination type and outcome",
), ),
@@ -130,6 +140,12 @@ impl Instruments {
#[must_use] #[must_use]
pub fn duration_buckets() -> Vec<f64> { (0..16).map(|i| 0.001 * f64::from(1_u32 << i)).collect() } pub fn duration_buckets() -> Vec<f64> { (0..16).map(|i| 0.001 * f64::from(1_u32 << i)).collect() }
/// Federation requests and transactions can run past the 60s default
/// `federation_timeout`.
fn long_duration_buckets() -> Vec<f64> {
(0..18).map(|i| 0.001 * f64::from(1_u32 << i)).collect()
}
fn size_buckets() -> Vec<f64> { (0..11).map(|i| 1024.0 * f64::from(4_u32.pow(i))).collect() } fn size_buckets() -> Vec<f64> { (0..11).map(|i| 1024.0 * f64::from(4_u32.pow(i))).collect() }
fn register_process(meter: &Meter) { fn register_process(meter: &Meter) {
-13
View File
@@ -8,19 +8,6 @@ pub mod info;
pub mod log; pub mod log;
pub mod matrix; pub mod matrix;
pub mod metrics; pub mod metrics;
pub mod mods;
#[cfg(any(not(conduwuit_mods), not(feature = "conduwuit_mods")))]
pub mod mods {
#[macro_export]
macro_rules! mod_ctor {
() => {};
}
#[macro_export]
macro_rules! mod_dtor {
() => {};
}
}
pub mod server; pub mod server;
pub mod utils; pub mod utils;
-28
View File
@@ -1,28 +0,0 @@
use std::sync::atomic::{AtomicI32, Ordering};
const ORDERING: Ordering = Ordering::Relaxed;
static STATIC_DTORS: AtomicI32 = AtomicI32::new(0);
/// Called by Module::unload() to indicate module is about to be unloaded and
/// static destruction is intended. This will allow verifying it actually took
/// place.
pub(crate) fn prepare() {
let count = STATIC_DTORS.fetch_sub(1, ORDERING);
debug_assert!(count <= 0, "STATIC_DTORS should not be greater than zero.");
}
/// Called by static destructor of a module. This call should only be found
/// inside a mod_fini! macro. Do not call from anywhere else.
#[inline(always)]
pub fn report() { let _count = STATIC_DTORS.fetch_add(1, ORDERING); }
/// Called by Module::unload() (see check()) with action in case a check()
/// failed. This can allow a stuck module to be noted while allowing for other
/// independent modules to be diagnosed.
pub(crate) fn check_and_reset() -> bool { STATIC_DTORS.swap(0, ORDERING) == 0 }
/// Called by Module::unload() after unload to verify static destruction took
/// place. A call to prepare() must be made prior to Module::unload() and making
/// this call.
#[allow(dead_code)]
pub(crate) fn check() -> bool { STATIC_DTORS.load(ORDERING) == 0 }
-44
View File
@@ -1,44 +0,0 @@
#[macro_export]
macro_rules! mod_ctor {
( $($body:block)? ) => {
$crate::mod_init! {{
$crate::debug_info!("Module loaded");
$($body)?
}}
}
}
#[macro_export]
macro_rules! mod_dtor {
( $($body:block)? ) => {
$crate::mod_fini! {{
$crate::debug_info!("Module unloading");
$($body)?
$crate::mods::canary::report();
}}
}
}
#[macro_export]
macro_rules! mod_init {
($body:block) => {
#[used]
#[cfg_attr(target_family = "unix", unsafe(link_section = ".init_array"))]
static MOD_INIT: unsafe extern "C" fn() = { _mod_init };
#[cfg_attr(target_family = "unix", unsafe(link_section = ".text.startup"))]
unsafe extern "C" fn _mod_init() -> () $body
};
}
#[macro_export]
macro_rules! mod_fini {
($body:block) => {
#[used]
#[cfg_attr(target_family = "unix", unsafe(link_section = ".fini_array"))]
static MOD_FINI: unsafe extern "C" fn() = { _mod_fini };
#[cfg_attr(target_family = "unix", unsafe(link_section = ".text.startup"))]
unsafe extern "C" fn _mod_fini() -> () $body
};
}
-11
View File
@@ -1,11 +0,0 @@
#![cfg(all(conduwuit_mods, feature = "conduwuit_mods"))]
pub(crate) use libloading::os::unix::{Library, Symbol};
pub mod canary;
pub mod macros;
pub mod module;
pub mod new;
pub mod path;
pub use module::Module;
-75
View File
@@ -1,75 +0,0 @@
use std::{
ffi::{CString, OsString},
time::SystemTime,
};
use super::{Library, Symbol, canary, new, path};
use crate::{Result, error};
pub struct Module {
handle: Option<Library>,
loaded: SystemTime,
path: OsString,
}
impl Module {
pub fn from_name(name: &str) -> Result<Self> { Self::from_path(path::from_name(name)?) }
pub fn from_path(path: OsString) -> Result<Self> {
Ok(Self {
handle: Some(new::from_path(&path)?),
loaded: SystemTime::now(),
path,
})
}
pub fn unload(&mut self) {
canary::prepare();
self.close();
if !canary::check_and_reset() {
let name = self.name().expect("Module is named");
error!("Module {name:?} is stuck and failed to unload.");
}
}
pub(crate) fn close(&mut self) {
if let Some(handle) = self.handle.take() {
handle.close().expect("Module handle closed");
}
}
pub fn get<Prototype>(&self, name: &str) -> Result<Symbol<Prototype>> {
let cname = CString::new(name.to_owned()).expect("terminated string from provided name");
let handle = self
.handle
.as_ref()
.expect("backing library loaded by this instance");
// SAFETY: Calls dlsym(3) on unix platforms. This might not have to be
// unsafe if wrapped in libloading with_dlerror().
let sym = unsafe { handle.get::<Prototype>(cname.as_bytes()) };
let sym = sym.expect("symbol found; binding successful");
Ok(sym)
}
pub fn deleted(&self) -> Result<bool> {
let mtime = path::mtime(self.path())?;
let res = mtime > self.loaded;
Ok(res)
}
pub fn name(&self) -> Result<String> { path::to_name(self.path()) }
#[must_use]
pub fn path(&self) -> &OsString { &self.path }
}
impl Drop for Module {
fn drop(&mut self) {
if self.handle.is_some() {
self.unload();
}
}
}
-23
View File
@@ -1,23 +0,0 @@
use std::ffi::OsStr;
use super::{Library, path};
use crate::{Err, Result};
const OPEN_FLAGS: i32 = libloading::os::unix::RTLD_LAZY | libloading::os::unix::RTLD_GLOBAL;
pub fn from_name(name: &str) -> Result<Library> {
let path = path::from_name(name)?;
from_path(&path)
}
pub fn from_path(path: &OsStr) -> Result<Library> {
//SAFETY: Calls dlopen(3) on unix platforms. This might not have to be
// unsafe if wrapped in with_dlerror.
let lib = unsafe { Library::open(Some(path), OPEN_FLAGS) };
if let Err(e) = lib {
let name = path::to_name(path)?;
return Err!("Loading module {name:?} failed: {e}");
}
Ok(lib.expect("module loaded"))
}
-41
View File
@@ -1,41 +0,0 @@
use std::{
env::current_exe,
ffi::{OsStr, OsString},
path::{Path, PathBuf},
time::SystemTime,
};
use libloading::library_filename;
use crate::Result;
pub fn from_name(name: &str) -> Result<OsString> {
let root = PathBuf::new();
let exe_path = current_exe()?;
let exe_dir = exe_path.parent().unwrap_or(&root);
let mut mod_path = exe_dir.to_path_buf();
let mod_file = library_filename(name);
mod_path.push(mod_file);
Ok(mod_path.into_os_string())
}
pub fn to_name(path: &OsStr) -> Result<String> {
let path = Path::new(path);
let name = path
.file_stem()
.expect("path file stem")
.to_str()
.expect("name string");
let name = name.strip_prefix("lib").unwrap_or(name).to_owned();
Ok(name)
}
pub fn mtime(path: &OsStr) -> Result<SystemTime> {
let meta = std::fs::metadata(path)?;
let mtime = meta.modified()?;
Ok(mtime)
}
-27
View File
@@ -27,10 +27,6 @@ pub struct Server {
/// observable used on shutdown and should not be modified. /// observable used on shutdown and should not be modified.
pub stopping: AtomicBool, pub stopping: AtomicBool,
/// Reload/shutdown desired indicator; when false, shutdown is desired. This
/// is an observable used on shutdown and modifying is not recommended.
pub reloading: AtomicBool,
/// Restart desired; when true, restart it desired after shutdown. /// Restart desired; when true, restart it desired after shutdown.
pub restarting: AtomicBool, pub restarting: AtomicBool,
@@ -60,7 +56,6 @@ impl Server {
config: config::Manager::new(config), config: config::Manager::new(config),
started: SystemTime::now(), started: SystemTime::now(),
stopping: AtomicBool::new(false), stopping: AtomicBool::new(false),
reloading: AtomicBool::new(false),
restarting: AtomicBool::new(false), restarting: AtomicBool::new(false),
runtime, runtime,
signal: broadcast::channel::<&'static str>(1).0, signal: broadcast::channel::<&'static str>(1).0,
@@ -69,25 +64,6 @@ impl Server {
} }
} }
pub fn reload(&self) -> Result<()> {
if cfg!(any(not(conduwuit_mods), not(feature = "conduwuit_mods"))) {
return Err!("Reloading not enabled");
}
if self.reloading.swap(true, Ordering::AcqRel) {
return Err!("Reloading already in progress");
}
if self.stopping.swap(true, Ordering::AcqRel) {
return Err!("Shutdown already in progress");
}
self.signal("SIGINT").inspect_err(|_| {
self.stopping.store(false, Ordering::Release);
self.reloading.store(false, Ordering::Release);
})
}
pub fn restart(&self) -> Result { pub fn restart(&self) -> Result {
if self.restarting.swap(true, Ordering::AcqRel) { if self.restarting.swap(true, Ordering::AcqRel) {
return Err!("Restart already in progress"); return Err!("Restart already in progress");
@@ -146,9 +122,6 @@ impl Server {
#[inline] #[inline]
pub fn is_stopping(&self) -> bool { self.stopping.load(Ordering::Relaxed) } pub fn is_stopping(&self) -> bool { self.stopping.load(Ordering::Relaxed) }
#[inline]
pub fn is_reloading(&self) -> bool { self.reloading.load(Ordering::Relaxed) }
#[inline] #[inline]
pub fn is_restarting(&self) -> bool { self.restarting.load(Ordering::Relaxed) } pub fn is_restarting(&self) -> bool { self.restarting.load(Ordering::Relaxed) }
+47 -3
View File
@@ -62,14 +62,28 @@ macro_rules! validated {
} }
#[inline] #[inline]
#[allow(clippy::as_conversions)] #[allow(clippy::as_conversions, clippy::cast_possible_truncation, clippy::cast_sign_loss)]
pub fn usize_from_f64(val: f64) -> Result<usize, Error> { pub fn usize_from_f64(val: f64) -> Result<usize, Error> {
// Exclusive upper bound for values whose truncation fits in `usize`.
// Note that `usize::MAX as f64` rounds up to 2^64 on 64-bit targets, so a
// strict `<` check against 2^(usize::BITS) rejects all out-of-range values
// on both 32-bit and 64-bit targets.
#[allow(clippy::cast_precision_loss)]
const MAX_USIZE_EXCLUSIVE: f64 = (1_u128 << usize::BITS) as f64;
if !val.is_finite() {
return Err!(Arithmetic("Converting non-finite float to unsigned integer"));
}
if val < 0.0 { if val < 0.0 {
return Err!(Arithmetic("Converting negative float to unsigned integer")); return Err!(Arithmetic("Converting negative float to unsigned integer"));
} }
//SAFETY: <https://doc.rust-lang.org/std/primitive.f64.html#method.to_int_unchecked> if val >= MAX_USIZE_EXCLUSIVE {
Ok(unsafe { val.to_int_unchecked::<usize>() }) return Err!(Arithmetic("Converting out-of-range float to unsigned integer"));
}
Ok(val as usize)
} }
#[inline] #[inline]
@@ -111,3 +125,33 @@ fn try_into_err<Dst: TryFrom<Src>, Src>(e: <Dst as TryFrom<Src>>::Error) -> Erro
#[inline] #[inline]
pub fn clamp<T: Ord>(val: T, min: T, max: T) -> T { cmp::min(cmp::max(val, min), max) } pub fn clamp<T: Ord>(val: T, min: T, max: T) -> T { cmp::min(cmp::max(val, min), max) }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn usize_from_f64_valid() {
assert_eq!(usize_from_f64(0.0).unwrap(), 0);
assert_eq!(usize_from_f64(-0.0).unwrap(), 0);
assert_eq!(usize_from_f64(42.9).unwrap(), 42);
assert_eq!(usize_from_f64(1_048_576.0).unwrap(), 1_048_576);
}
#[test]
fn usize_from_f64_rejects_invalid() {
usize_from_f64(-1.0).unwrap_err();
usize_from_f64(-0.5).unwrap_err();
usize_from_f64(f64::NAN).unwrap_err();
usize_from_f64(f64::INFINITY).unwrap_err();
usize_from_f64(f64::NEG_INFINITY).unwrap_err();
usize_from_f64(1e30).unwrap_err();
#[cfg(target_pointer_width = "64")]
{
// `usize::MAX as f64` rounds up to 2^64, which is out of range.
#[allow(clippy::as_conversions, clippy::cast_precision_loss)]
let rounded_max = usize::MAX as f64;
usize_from_f64(rounded_max).unwrap_err();
}
}
}
+3 -5
View File
@@ -1,7 +1,6 @@
use std::convert::Infallible; use std::convert::Infallible;
use super::{DebugInspect, Result}; use super::Result;
use crate::error;
pub trait UnwrapInfallible<T> { pub trait UnwrapInfallible<T> {
fn unwrap_infallible(self) -> T; fn unwrap_infallible(self) -> T;
@@ -10,8 +9,7 @@ pub trait UnwrapInfallible<T> {
impl<T> UnwrapInfallible<T> for Result<T, Infallible> { impl<T> UnwrapInfallible<T> for Result<T, Infallible> {
#[inline] #[inline]
fn unwrap_infallible(self) -> T { fn unwrap_infallible(self) -> T {
// SAFETY: Branchless unwrap for errors that can never happen. In debug let Ok(val) = self;
// mode this is asserted. val
unsafe { self.debug_inspect_err(error::infallible).unwrap_unchecked() }
} }
} }
+5 -4
View File
@@ -32,11 +32,12 @@ impl<'a> From<&'a str> for &'a Unquoted {
fn from(s: &'a str) -> &'a Unquoted { fn from(s: &'a str) -> &'a Unquoted {
let s: &'a str = s.unquote_infallible(); let s: &'a str = s.unquote_infallible();
//SAFETY: This is a pattern I lifted from ruma-identifiers for // SAFETY: `Unquoted` is `#[repr(transparent)]` over `str`, so
// strong-type strs by wrapping in a tuple-struct. // `*const str` and `*const Unquoted` have identical layout and
#[allow(clippy::transmute_ptr_to_ptr)] // metadata, and the returned reference preserves lifetime `'a`.
#[allow(clippy::as_conversions)]
unsafe { unsafe {
std::mem::transmute(s) &*(std::ptr::from_ref::<str>(s) as *const Unquoted)
} }
} }
} }
+5 -13
View File
@@ -120,21 +120,13 @@ pub fn cores_available() -> impl Iterator<Item = Id> { from_mask(*CORES_AVAILABL
pub fn getcpu() -> Result<usize> { pub fn getcpu() -> Result<usize> {
use crate::{Error, utils::math}; use crate::{Error, utils::math};
// SAFETY: This is part of an interface with many low-level calls taking // SAFETY: `sched_getcpu(2)` takes no pointers and has no preconditions.
// many raw params, but it's unclear why this specific call is unsafe. // Note that it may still return -1 with errno set (e.g. under seccomp
// Nevertheless the value obtained here is semantically unsafe because it // filters or kernels without getcpu support), so the error branch below
// can change on the instruction boundary trailing its own acquisition and // must remain live.
// also any other time.
let ret: i32 = unsafe { libc::sched_getcpu() }; let ret: i32 = unsafe { libc::sched_getcpu() };
#[cfg(target_os = "linux")] if ret < 0 {
// SAFETY: On modern linux systems with a vdso if we can optimize away the branch checking
// for error (see getcpu(2)) then this system call becomes a memory access.
unsafe {
std::hint::assert_unchecked(ret >= 0);
};
if ret == -1 {
return Err(Error::from_errno()); return Err(Error::from_errno());
} }
-12
View File
@@ -472,17 +472,5 @@ impl<'a, 'de: 'a> de::MapAccess<'de> for &'a mut Deserializer<'de> {
} }
} }
// activate when stable; too soon now
//#[cfg(debug_assertions)]
#[inline] #[inline]
fn deserialize_str(input: &[u8]) -> Result<&str> { string::str_from_bytes(input) } fn deserialize_str(input: &[u8]) -> Result<&str> { string::str_from_bytes(input) }
//#[cfg(not(debug_assertions))]
#[cfg(disable)]
#[inline]
fn deserialize_str(input: &[u8]) -> Result<&str> {
// SAFETY: Strings were written by the serializer to the database. Assuming
// no database corruption, the string will be valid. Database corruption is
// detected via rocksdb checksums.
unsafe { std::str::from_utf8_unchecked(input) }
}
+4
View File
@@ -46,6 +46,10 @@ use crate::{Engine, watchers::Watchers};
pub struct Map { pub struct Map {
name: &'static str, name: &'static str,
watchers: Watchers, watchers: Watchers,
/// SAFETY / DROP ORDER: `cf` holds a lifetime-erased RocksDB column family
/// handle (see `open::open`) and MUST be declared before `db` so that the
/// handle is destroyed before `Engine` (and the underlying RocksDB `DB`)
/// can be dropped.
cf: Arc<ColumnFamily>, cf: Arc<ColumnFamily>,
db: Arc<Engine>, db: Arc<Engine>,
read_options: ReadOptions, read_options: ReadOptions,
+15 -1
View File
@@ -1,10 +1,24 @@
use std::sync::Arc; use std::sync::Arc;
use rocksdb::ColumnFamily; use rocksdb::{BoundColumnFamily, ColumnFamily};
use crate::Engine; use crate::Engine;
pub(super) fn open(db: &Arc<Engine>, name: &str) -> Arc<ColumnFamily> { pub(super) fn open(db: &Arc<Engine>, name: &str) -> Arc<ColumnFamily> {
// Compile-time guard: `BoundColumnFamily` and `ColumnFamily` are both
// `#[repr(Rust)]` in `rust-rocksdb`, so fail compilation if their size or
// alignment ever diverge.
const {
assert!(
size_of::<BoundColumnFamily<'_>>() == size_of::<ColumnFamily>(),
"BoundColumnFamily and ColumnFamily must have identical size"
);
assert!(
align_of::<BoundColumnFamily<'_>>() == align_of::<ColumnFamily>(),
"BoundColumnFamily and ColumnFamily must have identical alignment"
);
}
let bounded_arc = db.cf(name); let bounded_arc = db.cf(name);
let bounded_ptr = Arc::into_raw(bounded_arc); let bounded_ptr = Arc::into_raw(bounded_arc);
let cf_ptr = bounded_ptr.cast::<ColumnFamily>(); let cf_ptr = bounded_ptr.cast::<ColumnFamily>();
+11
View File
@@ -12,6 +12,17 @@ impl super::Map {
/// Iterate key-value entries in the map from the beginning. /// Iterate key-value entries in the map from the beginning.
/// ///
/// - Result is deserialized /// - Result is deserialized
///
/// # Unsoundness
/// Because Rust's `Stream` trait does not support lending items tied to
/// `&mut self`, `stream::slice_longevity` unsafely extends the lifetime of
/// raw RocksDB iterator slices to `'a` (the borrow of `Arc<Map>`). As a
/// consequence, borrowed deserialized types (e.g. `&str`, `&UserId`,
/// `&[u8]`) reference the underlying RocksDB cursor buffer and are
/// invalidated on the next poll of the stream. Do not hold borrowed items
/// across polls (e.g. via `collect()`, `ready_chunks()`, `peekable()`,
/// `buffered()`, `buffer_unordered()`, `broadband`, or `wideband`) without
/// converting them to owned values first.
pub fn stream<'a, K, V>( pub fn stream<'a, K, V>(
self: &'a Arc<Self>, self: &'a Arc<Self>,
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send ) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send
-3
View File
@@ -5,9 +5,6 @@ extern crate rust_rocksdb as rocksdb;
conduwuit_macros::introspect_crate! {} conduwuit_macros::introspect_crate! {}
conduwuit::mod_ctor! {}
conduwuit::mod_dtor! {}
#[cfg(test)] #[cfg(test)]
mod benches; mod benches;
mod cork; mod cork;
+23 -11
View File
@@ -54,8 +54,14 @@ pub(crate) struct Get {
/// Note: only initial seek is supported at this time on the assumption rocksdb /// Note: only initial seek is supported at this time on the assumption rocksdb
/// prefetching prevents mid-iteration polls from blocking on I/O. /// prefetching prevents mid-iteration polls from blocking on I/O.
pub(crate) struct Seek { pub(crate) struct Seek {
pub(crate) map: Arc<Map>, /// SAFETY / DROP ORDER: `state` wraps a RocksDB
/// `DBRawIteratorWithThreadMode` referencing `map.db.db` whose lifetime has
/// been erased to `'static`. `state` MUST be declared before `map` so the
/// iterator is destroyed before `map` (and potentially the last
/// `Arc<Engine>`) can be dropped if `Seek` is dropped early (e.g. on
/// cancellation or queue closure).
pub(crate) state: stream::State<'static>, pub(crate) state: stream::State<'static>,
pub(crate) map: Arc<Map>,
pub(crate) dir: Direction, pub(crate) dir: Direction,
pub(crate) key: Option<KeyBuf>, pub(crate) key: Option<KeyBuf>,
pub(crate) res: Option<ResultSender<stream::State<'static>>>, pub(crate) res: Option<ResultSender<stream::State<'static>>>,
@@ -416,24 +422,30 @@ impl Drop for Pool {
} }
fn into_send_get(result: BatchResult<'_>) -> BatchResult<'static> { fn into_send_get(result: BatchResult<'_>) -> BatchResult<'static> {
// SAFETY: Necessary to send the Handle (rust_rocksdb::PinnableSlice) // SAFETY: Necessary to send `Handle` (which wraps
// through the channel. The lifetime on the handle is a device by // `rocksdb::DBPinnableSlice`) through the oneshot channel. The lifetime on
// rust-rocksdb to associate a database lifetime with its assets. The // `Handle` ties it to the RocksDB `DB` instance; callers of `execute_get`
// Handle must be dropped before the database is dropped. // borrow `&self.db.pool` (which is owned by `Engine`), ensuring the
// received `BatchResult<'_>` cannot outlive the database.
unsafe { std::mem::transmute(result) } unsafe { std::mem::transmute(result) }
} }
fn into_recv_get<'a>(result: BatchResult<'static>) -> BatchResult<'a> { fn into_recv_get<'a>(result: BatchResult<'static>) -> BatchResult<'a> {
// SAFETY: This is to receive the Handle from the channel. // SAFETY: Shrinking the erased `'static` lifetime back to `'a` (borrowed
// from `&self.db.pool`). `SmallVec<A>` is invariant over `A`, so this
// cannot be done via implicit covariance.
unsafe { std::mem::transmute(result) } unsafe { std::mem::transmute(result) }
} }
pub(crate) fn into_send_seek(result: stream::State<'_>) -> stream::State<'static> { pub(crate) fn into_send_seek(result: stream::State<'_>) -> stream::State<'static> {
// SAFETY: Necessary to send the State through the channel; see above. // SAFETY: Necessary to send `stream::State` through the pool channel.
// While in flight on the queue, `Seek` owns an `Arc<Map>` (declared after
// `state` so `state` drops first on early cancellation); once received back
// from `execute_iter`, the lifetime is shrunk via `into_recv_seek` to the
// caller's borrow of `&self.db.pool` (and `&'a Arc<Map>`), ensuring the
// returned `stream::State<'_>` cannot outlive the database.
unsafe { std::mem::transmute(result) } unsafe { std::mem::transmute(result) }
} }
fn into_recv_seek(result: stream::State<'static>) -> stream::State<'static> { #[inline]
// SAFETY: This is to receive the State from the channel; see above. const fn into_recv_seek<'a>(result: stream::State<'static>) -> stream::State<'a> { result }
unsafe { std::mem::transmute(result) }
}
+14 -16
View File
@@ -133,22 +133,20 @@ fn keyval_longevity<'a, 'b: 'a>(item: KeyVal<'a>) -> KeyVal<'b> {
} }
fn slice_longevity<'a, 'b: 'a>(item: &'a Slice) -> &'b Slice { fn slice_longevity<'a, 'b: 'a>(item: &'a Slice) -> &'b Slice {
// SAFETY: The lifetime of the data returned by the rocksdb cursor is only // SAFETY: the lifetime of the data returned by
// valid between each movement of the cursor. It is hereby unsafely // the RocksDB cursor is only valid until the next movement of the cursor,
// extended to match the lifetime of the cursor itself. This is due to the // but is unsafely extended here to match the lifetime `'b` of the `Map`
// limitation of the Stream trait where the Item is incapable of conveying // borrow because `futures::Stream` is not a lending stream.
// a lifetime; this is due to GAT's being unstable during its development.
// This unsafety can be removed as soon as this limitation is addressed by
// an upcoming version.
// //
// We have done our best to mitigate the implications of this in conjunction // Callers MUST NOT hold borrowed items (or borrowed deserialized views such
// with the deserialization API such that borrows being held across // as `&str`, `&UserId`, or `&[u8]`) across subsequent polls of the stream —
// movements of the cursor do not happen accidentally. The compiler will // in particular, never call `collect()`, `ready_chunks()`, `peekable()`,
// still error when values herein produced try to leave a closure passed to // `buffered()`, `buffer_unordered()`, `broadband`, or `wideband` on a
// a StreamExt API. But escapes can happen if you explicitly and // stream yielding borrowed references without first converting items to
// intentionally attempt it, and there will be no compiler error or // owned values (e.g. `map(ToOwned::to_owned)`). The compiler does NOT
// warning. This is primarily the case with calling collect() without a // reject such escapes when items borrow from `'b`.
// preceding map(ToOwned::to_owned). A collection of references here is //
// illegal, but this will not be enforced by the compiler. // TODO: Fix this, it is old code and language changes may have made it
// unnecessary
unsafe { std::mem::transmute(item) } unsafe { std::mem::transmute(item) }
} }
-16
View File
@@ -1,28 +1,12 @@
use conduwuit::Result; use conduwuit::Result;
use rocksdb::{Direction, ErrorKind, IteratorMode}; use rocksdb::{Direction, ErrorKind, IteratorMode};
//#[cfg(debug_assertions)]
macro_rules! unhandled { macro_rules! unhandled {
($msg:literal) => { ($msg:literal) => {
unimplemented!($msg) unimplemented!($msg)
}; };
} }
// activate when stable; we're not ready for this yet
#[cfg(disable)] // #[cfg(not(debug_assertions))]
macro_rules! unhandled {
($msg:literal) => {
// SAFETY: Eliminates branches for serializing and deserializing types never
// encountered in the codebase. This can promote optimization and reduce
// codegen. The developer must verify for every invoking callsite that the
// unhandled type is in no way involved and could not possibly be
// encountered.
unsafe {
std::hint::unreachable_unchecked();
}
};
}
pub(crate) use unhandled; pub(crate) use unhandled;
#[inline] #[inline]
-3
View File
@@ -175,9 +175,6 @@ zstd_compression = [
"conduwuit-router/zstd_compression", "conduwuit-router/zstd_compression",
"conduwuit-service/zstd_compression", "conduwuit-service/zstd_compression",
] ]
conduwuit_mods = [
"conduwuit-core/conduwuit_mods",
]
bindgen-static = [ bindgen-static = [
# "bindgen/static" # "bindgen/static"
# "clang-sys/static" # "clang-sys/static"
+8 -11
View File
@@ -26,18 +26,15 @@ pub(crate) fn init(
let mut builder = SdkMeterProvider::builder() let mut builder = SdkMeterProvider::builder()
.with_resource(resource) .with_resource(resource)
.with_view(|instrument: &Instrument| { .with_view(|instrument: &Instrument| match instrument.name() {
(instrument.name() == metric::HTTP_SERVER_REQUEST_DURATION) | metric::HTTP_SERVER_REQUEST_DURATION => Stream::builder()
.then(|| { .with_aggregation(Aggregation::ExplicitBucketHistogram {
Stream::builder() boundaries: duration_buckets(),
.with_aggregation(Aggregation::ExplicitBucketHistogram { record_min_max: true,
boundaries: duration_buckets(),
record_min_max: true,
})
.build()
.ok()
}) })
.flatten() .build()
.ok(),
| _ => None,
}); });
let registry = config let registry = config
+2 -38
View File
@@ -10,7 +10,6 @@ mod clap;
mod deadlock; mod deadlock;
mod logging; mod logging;
mod metrics; mod metrics;
mod mods;
mod panic; mod panic;
mod restart; mod restart;
mod runtime; mod runtime;
@@ -63,9 +62,8 @@ pub fn run_with_args(args: &Args) -> Result<()> {
Ok(()) Ok(())
} }
/// Operate the server normally in release-mode static builds. This will start, /// Operate the server. This will start, run and stop the server within the
/// run and stop the server within the asynchronous runtime. /// asynchronous runtime.
#[cfg(any(not(conduwuit_mods), not(feature = "conduwuit_mods")))]
#[tracing::instrument( #[tracing::instrument(
name = "main", name = "main",
parent = None, parent = None,
@@ -114,37 +112,3 @@ async fn async_main(server: &Arc<Server>) -> Result<(), Error> {
debug_info!("Exit runtime"); debug_info!("Exit runtime");
Ok(()) Ok(())
} }
/// Operate the server in developer-mode dynamic builds. This will start, run,
/// and hot-reload portions of the server as-needed before returning for an
/// actual shutdown. This is not available in release-mode or static builds.
#[cfg(all(conduwuit_mods, feature = "conduwuit_mods"))]
async fn async_main(server: &Arc<Server>) -> Result<(), Error> {
let mut starts = true;
let mut reloads = true;
while reloads {
if let Err(error) = mods::open(server).await {
error!("Loading router: {error}");
return Err(error);
}
let result = mods::run(server, starts).await;
if let Ok(result) = result {
(starts, reloads) = result;
}
let force = !reloads || result.is_err();
if let Err(error) = mods::close(server, force).await {
error!("Unloading router: {error}");
return Err(error);
}
if let Err(error) = result {
error!("{error}");
return Err(error);
}
}
debug_info!("Exit runtime");
Ok(())
}
-163
View File
@@ -1,163 +0,0 @@
#![cfg(all(conduwuit_mods, feature = "conduwuit_mods"))]
#[unsafe(no_link)]
extern crate conduwuit_service;
use std::{
future::Future,
pin::Pin,
sync::{Arc, atomic::Ordering},
};
use conduwuit_core::{Error, Result, debug, error, mods};
use conduwuit_service::Services;
use crate::Server;
type StartFuncResult = Pin<Box<dyn Future<Output = Result<Arc<Services>>> + Send>>;
type StartFuncProto = fn(&Arc<conduwuit_core::Server>) -> StartFuncResult;
type RunFuncResult = Pin<Box<dyn Future<Output = Result<()>> + Send>>;
type RunFuncProto = fn(&Arc<Services>) -> RunFuncResult;
type StopFuncResult = Pin<Box<dyn Future<Output = Result<()>> + Send>>;
type StopFuncProto = fn(Arc<Services>) -> StopFuncResult;
const RESTART_THRESH: &str = "conduwuit_service";
const MODULE_NAMES: &[&str] = &[
//"conduwuit_core",
"conduwuit_database",
"conduwuit_service",
"conduwuit_api",
"conduwuit_admin",
"conduwuit_router",
];
#[cfg(panic_trap)]
conduwuit_core::mod_init! {{
conduwuit_core::debug::set_panic_trap();
}}
pub(crate) async fn run(server: &Arc<Server>, starts: bool) -> Result<(bool, bool), Error> {
let main_lock = server.mods.read().await;
let main_mod = (*main_lock).last().expect("main module loaded");
if starts {
let start = main_mod.get::<StartFuncProto>("start")?;
match start(&server.server).await {
| Ok(services) => server.services.lock().await.insert(services),
| Err(error) => {
error!("Starting server: {error}");
return Err(error);
},
};
}
server.server.stopping.store(false, Ordering::Release);
let run = main_mod.get::<RunFuncProto>("run")?;
if let Err(error) = run(server
.services
.lock()
.await
.as_ref()
.expect("services initialized"))
.await
{
error!("Running server: {error}");
return Err(error);
}
let reloads = server.server.reloading.swap(false, Ordering::AcqRel);
let stops = !reloads || stale_from_mods(&main_lock)? <= restart_thresh();
let starts = reloads && stops;
if stops {
let stop = main_mod.get::<StopFuncProto>("stop")?;
if let Err(error) = stop(
server
.services
.lock()
.await
.take()
.expect("services initialized"),
)
.await
{
error!("Stopping server: {error}");
return Err(error);
}
}
Ok((starts, reloads))
}
pub(crate) async fn open(server: &Arc<Server>) -> Result<usize, Error> {
let mut mods_lock = server.mods.write().await;
let mods: &mut Vec<mods::Module> = &mut mods_lock;
debug!(
available = %available(),
loaded = %mods.len(),
"Loading modules",
);
for (i, name) in MODULE_NAMES.iter().enumerate() {
if mods.get(i).is_none() {
mods.push(mods::Module::from_name(name)?);
}
}
Ok(mods.len())
}
pub(crate) async fn close(server: &Arc<Server>, force: bool) -> Result<usize, Error> {
let stale = stale_count(server).await;
let mut mods_lock = server.mods.write().await;
let mods: &mut Vec<mods::Module> = &mut mods_lock;
debug!(
available = %available(),
loaded = %mods.len(),
stale = %stale,
force,
"Unloading modules",
);
while mods.last().is_some() {
let module = &mods.last().expect("module");
if force || module.deleted()? {
mods.pop();
} else {
break;
}
}
Ok(mods.len())
}
async fn stale_count(server: &Arc<Server>) -> usize {
let watermark = stale(server).await.unwrap_or(available());
available().saturating_sub(watermark)
}
async fn stale(server: &Arc<Server>) -> Result<usize, Error> {
let mods_lock = server.mods.read().await;
stale_from_mods(&mods_lock)
}
fn stale_from_mods(mods: &[mods::Module]) -> Result<usize, Error> {
for (i, module) in mods.iter().enumerate() {
if module.deleted()? {
return Ok(i);
}
}
Ok(mods.len())
}
fn restart_thresh() -> usize {
MODULE_NAMES
.iter()
.position(|&name| name.ends_with(RESTART_THRESH))
.unwrap_or(MODULE_NAMES.len())
}
const fn available() -> usize { MODULE_NAMES.len() }
-7
View File
@@ -27,10 +27,6 @@ pub(crate) struct Server {
#[cfg(feature = "sentry_telemetry")] #[cfg(feature = "sentry_telemetry")]
_sentry_guard: Option<::sentry::ClientInitGuard>, _sentry_guard: Option<::sentry::ClientInitGuard>,
#[cfg(all(conduwuit_mods, feature = "conduwuit_mods"))]
// Module instances; TODO: move to mods::loaded mgmt vector
pub(crate) mods: tokio::sync::RwLock<Vec<conduwuit_core::mods::Module>>,
} }
impl Server { impl Server {
@@ -87,9 +83,6 @@ impl Server {
#[cfg(feature = "sentry_telemetry")] #[cfg(feature = "sentry_telemetry")]
_sentry_guard: sentry_guard, _sentry_guard: sentry_guard,
#[cfg(all(conduwuit_mods, feature = "conduwuit_mods"))]
mods: tokio::sync::RwLock::new(Vec::new()),
})) }))
} }
+1 -4
View File
@@ -12,7 +12,6 @@ pub(super) async fn signal(server: Arc<Server>) {
use unix::SignalKind; use unix::SignalKind;
const CONSOLE: bool = cfg!(feature = "console"); const CONSOLE: bool = cfg!(feature = "console");
const RELOADING: bool = cfg!(all(conduwuit_mods, feature = "conduwuit_mods", not(CONSOLE)));
let mut quit = unix::signal(SignalKind::quit()).expect("SIGQUIT handler"); let mut quit = unix::signal(SignalKind::quit()).expect("SIGQUIT handler");
let mut term = unix::signal(SignalKind::terminate()).expect("SIGTERM handler"); let mut term = unix::signal(SignalKind::terminate()).expect("SIGTERM handler");
@@ -30,9 +29,7 @@ pub(super) async fn signal(server: Arc<Server>) {
} }
warn!("Received {sig}"); warn!("Received {sig}");
let result = if RELOADING && sig == "SIGINT" { let result = if matches!(sig, "SIGQUIT" | "SIGTERM") || (!CONSOLE && sig == "SIGINT") {
server.server.reload()
} else if matches!(sig, "SIGQUIT" | "SIGTERM") || (!CONSOLE && sig == "SIGINT") {
server.server.shutdown() server.server.shutdown()
} else { } else {
server.server.signal(sig) server.server.signal(sig)
+3 -13
View File
@@ -16,11 +16,7 @@ use conduwuit::{Error, Result, Server};
use conduwuit_service::Services; use conduwuit_service::Services;
use futures::{Future, FutureExt, TryFutureExt}; use futures::{Future, FutureExt, TryFutureExt};
conduwuit::mod_ctor! {} pub fn start(
conduwuit::mod_dtor! {}
#[unsafe(no_mangle)]
pub extern "Rust" fn start(
server: &Arc<Server>, server: &Arc<Server>,
) -> Pin<Box<dyn Future<Output = Result<Arc<Services>>> + Send>> { ) -> Pin<Box<dyn Future<Output = Result<Arc<Services>>> + Send>> {
AssertUnwindSafe(run::start(server.clone())) AssertUnwindSafe(run::start(server.clone()))
@@ -30,10 +26,7 @@ pub extern "Rust" fn start(
.boxed() .boxed()
} }
#[unsafe(no_mangle)] pub fn stop(services: Arc<Services>) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
pub extern "Rust" fn stop(
services: Arc<Services>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
AssertUnwindSafe(run::stop(services)) AssertUnwindSafe(run::stop(services))
.catch_unwind() .catch_unwind()
.map_err(Error::from_panic) .map_err(Error::from_panic)
@@ -41,10 +34,7 @@ pub extern "Rust" fn stop(
.boxed() .boxed()
} }
#[unsafe(no_mangle)] pub fn run(services: &Arc<Services>) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
pub extern "Rust" fn run(
services: &Arc<Services>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
AssertUnwindSafe(run::run(services.clone())) AssertUnwindSafe(run::run(services.clone()))
.catch_unwind() .catch_unwind()
.map_err(Error::from_panic) .map_err(Error::from_panic)
+6 -2
View File
@@ -64,7 +64,7 @@ pub(crate) async fn handle(
.server .server
.metrics .metrics
.requests_handle_active .requests_handle_active
.fetch_add(1, Ordering::Relaxed), .load(Ordering::Relaxed),
handled = %services handled = %services
.server .server
.metrics .metrics
@@ -81,7 +81,11 @@ async fn execute(
next: axum::middleware::Next, next: axum::middleware::Next,
parent: &Span, parent: &Span,
) -> Response { ) -> Response {
#[cfg(debug_assertions)] services
.server
.metrics
.requests_handle_active
.fetch_add(1, Ordering::Relaxed);
conduwuit::defer! {{ conduwuit::defer! {{
_ = services.server _ = services.server
.metrics .metrics
+5 -1
View File
@@ -8,7 +8,11 @@ use ruma::api::error::ErrorKind;
pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) { pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
let router = Router::<state::State>::new(); let router = Router::<state::State>::new();
let (state, guard) = state::create(services.clone()); // SAFETY: `guard` is returned alongside `router` and held in `serve()`
// until the HTTP server has finished serving all requests and dropped
// `router`, ensuring no `State` copy can be dereferenced after `Services`
// is dropped.
let (state, guard) = unsafe { state::create(services.clone()) };
let router = conduwuit_api::router::build(router, state) let router = conduwuit_api::router::build(router, state)
.merge(conduwuit_web::build(services)) .merge(conduwuit_web::build(services))
.fallback(not_found) .fallback(not_found)
+16 -8
View File
@@ -112,14 +112,27 @@ impl Service {
err!(Database(error!("Failed to write media file for MXC {mxc} at key {key:?}: {e}"))) err!(Database(error!("Failed to write media file for MXC {mxc} at key {key:?}: {e}")))
})?; })?;
self.record_write(mxc, file.len());
Ok(())
}
fn record_write(&self, mxc: &Mxc<'_>, len: usize) {
self.services self.services
.server .server
.metrics .metrics
.instruments .instruments
.media_write_size .media_write_size
.record(file.len().try_into().unwrap_or(u64::MAX), &[self.origin(mxc)]); .record(len.try_into().unwrap_or(u64::MAX), &[self.origin(mxc)]);
}
Ok(()) fn record_read(&self, mxc: &Mxc<'_>, len: usize) {
self.services
.server
.metrics
.instruments
.media_read_size
.record(len.try_into().unwrap_or(u64::MAX), &[self.origin(mxc)]);
} }
fn origin(&self, mxc: &Mxc<'_>) -> KeyValue { fn origin(&self, mxc: &Mxc<'_>) -> KeyValue {
@@ -196,12 +209,7 @@ impl Service {
.read_to_end(&mut content) .read_to_end(&mut content)
.await?; .await?;
self.services self.record_read(mxc, content.len());
.server
.metrics
.instruments
.media_read_size
.record(content.len().try_into().unwrap_or(u64::MAX), &[self.origin(mxc)]);
Ok(Some(FileMeta { Ok(Some(FileMeta {
content: Some(content), content: Some(content),
+9 -1
View File
@@ -44,6 +44,7 @@ impl super::Service {
//TODO: Dangling metadata in database if creation fails //TODO: Dangling metadata in database if creation fails
let mut f = self.create_media_file(&key).await?; let mut f = self.create_media_file(&key).await?;
f.write_all(file).await?; f.write_all(file).await?;
self.record_write(mxc, file.len());
Ok(()) Ok(())
} }
@@ -66,13 +67,19 @@ impl super::Service {
// 0, 0 because that's the original file // 0, 0 because that's the original file
let dim = dim.normalized(); let dim = dim.normalized();
match self.db.search_file_metadata(mxc, &dim).await { let thumbnail = match self.db.search_file_metadata(mxc, &dim).await {
| Ok(metadata) => self.get_thumbnail_saved(metadata).await, | Ok(metadata) => self.get_thumbnail_saved(metadata).await,
| _ => match self.db.search_file_metadata(mxc, &Dim::default()).await { | _ => match self.db.search_file_metadata(mxc, &Dim::default()).await {
| Ok(metadata) => self.get_thumbnail_generate(mxc, &dim, metadata).await, | Ok(metadata) => self.get_thumbnail_generate(mxc, &dim, metadata).await,
| _ => Ok(None), | _ => Ok(None),
}, },
};
if let Ok(Some(FileMeta { content: Some(content), .. })) = &thumbnail {
self.record_read(mxc, content.len());
} }
thumbnail
} }
/// Using saved thumbnail /// Using saved thumbnail
@@ -132,6 +139,7 @@ impl super::Service {
let mut f = self.create_media_file(&thumbnail_key).await?; let mut f = self.create_media_file(&thumbnail_key).await?;
f.write_all(&thumbnail_bytes).await?; f.write_all(&thumbnail_bytes).await?;
self.record_write(mxc, thumbnail_bytes.len());
Ok(Some(into_filemeta(data, thumbnail_bytes))) Ok(Some(into_filemeta(data, thumbnail_bytes)))
} }
+3 -9
View File
@@ -44,19 +44,13 @@ pub mod transactions;
pub mod uiaa; pub mod uiaa;
pub mod users; pub mod users;
use std::collections::BTreeMap; use std::{collections::BTreeMap, sync::LazyLock};
use conduwuit::matrix::versions::versions;
use ruma::api::SupportedVersions;
pub(crate) use service::{Args, Dep, Service}; pub(crate) use service::{Args, Dep, Service};
pub use crate::services::Services; pub use crate::services::Services;
conduwuit::mod_ctor! {}
conduwuit::mod_dtor! {}
use std::sync::LazyLock;
use conduwuit::matrix::versions::versions;
use ruma::api::SupportedVersions;
pub static SUPPORTED_VERSIONS: LazyLock<SupportedVersions> = pub static SUPPORTED_VERSIONS: LazyLock<SupportedVersions> =
LazyLock::new(|| SupportedVersions::from_parts(&versions(), &BTreeMap::new())); LazyLock::new(|| SupportedVersions::from_parts(&versions(), &BTreeMap::new()));
+3 -2
View File
@@ -1,4 +1,4 @@
use std::{collections::HashMap, str::FromStr, sync::Arc, time::Duration}; use std::{collections::HashMap, net::IpAddr, str::FromStr, sync::Arc, time::Duration};
use async_trait::async_trait; use async_trait::async_trait;
use conduwuit::{ use conduwuit::{
@@ -359,6 +359,7 @@ impl Service {
&self, &self,
claims: &Claims, claims: &Claims,
supplied_user_id: Option<OwnedUserId>, supplied_user_id: Option<OwnedUserId>,
client_ip: &IpAddr,
) -> Result<SessionCompletionStatus, &'static str> { ) -> Result<SessionCompletionStatus, &'static str> {
let Some(OidcClient { config, .. }) = self.client.as_ref() else { let Some(OidcClient { config, .. }) = self.client.as_ref() else {
return Err("Delegated authentication is not enabled on this server."); return Err("Delegated authentication is not enabled on this server.");
@@ -419,7 +420,7 @@ impl Service {
// Create a new shadow user // Create a new shadow user
self.services self.services
.users .users
.create_local_account(&user_id, None, None, None, None) .create_local_account(&user_id, None, None, Some(client_ip), None)
.await .await
.map_err(|err| { .map_err(|err| {
error!("Failed to create a shadow user for {user_id}: {err}"); error!("Failed to create a shadow user for {user_id}: {err}");
+9 -1
View File
@@ -11,7 +11,15 @@ pub struct Guard {
services: Arc<Services>, services: Arc<Services>,
} }
pub fn create(services: Arc<Services>) -> (State, Guard) { /// Create a raw-pointer `State` handle paired with a `Guard` that keeps
/// `Services` alive.
///
/// # Safety
/// `State` is `Copy` and dereferences its raw pointer without reference
/// counting. The caller must ensure that no `State` (nor any copy of it) is
/// dereferenced after `Guard` and all other `Arc<Services>` clones have been
/// dropped.
pub unsafe fn create(services: Arc<Services>) -> (State, Guard) {
let state = State { let state = State {
services: Arc::into_raw(services.clone()), services: Arc::into_raw(services.clone()),
}; };
+7 -2
View File
@@ -6,6 +6,7 @@ use axum::{
response::Redirect, response::Redirect,
routing::on, routing::on,
}; };
use conduwuit_api::client_ip::ClientIp;
use conduwuit_service::{ use conduwuit_service::{
oauth::grant::AuthorizationCodeResponse, oauth::grant::AuthorizationCodeResponse,
oidc::{ClaimedLocalUser, SessionCompletionStatus}, oidc::{ClaimedLocalUser, SessionCompletionStatus},
@@ -63,6 +64,7 @@ async fn route_complete(
Expect(Query(query)): Expect<Query<AuthorizationCodeResponse>>, Expect(Query(query)): Expect<Query<AuthorizationCodeResponse>>,
session_store: Session, session_store: Session,
user: User<true>, user: User<true>,
ClientIp(client_ip): ClientIp,
PostForm(form): PostForm<LoginForm>, PostForm(form): PostForm<LoginForm>,
) -> Result { ) -> Result {
let user_id = user.into_session().map(|session| session.user_id); let user_id = user.into_session().map(|session| session.user_id);
@@ -104,7 +106,10 @@ async fn route_complete(
.await .await
.expect("should be able to serialize oidc session"); .expect("should be able to serialize oidc session");
services.oidc.complete_session(&claims, None).await services
.oidc
.complete_session(&claims, None, &client_ip)
.await
}, },
| OidcSessionState::Authorized { claims } => { | OidcSessionState::Authorized { claims } => {
let supplied_user_id = if let Some(form) = form { let supplied_user_id = if let Some(form) = form {
@@ -163,7 +168,7 @@ async fn route_complete(
services services
.oidc .oidc
.complete_session(&claims, supplied_user_id) .complete_session(&claims, supplied_user_id, &client_ip)
.await .await
}, },
} }