mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-22 00:17:33 +00:00
Compare commits
32
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
beb78fa5d4 | ||
|
|
de9e9b28e2 | ||
|
|
fda99bcda2 | ||
|
|
5d66476126 | ||
|
|
798bef5bc7 | ||
|
|
7408d53977 | ||
|
|
973cfd5746 | ||
|
|
cb9b3e65d0 | ||
|
|
d4aec6ca5c | ||
|
|
43cf8cccdf | ||
|
|
c6b9854c49 | ||
|
|
6df7dda329 | ||
|
|
8a20a5c349 | ||
|
|
a27a5bed29 | ||
|
|
d4ac77a023 | ||
|
|
68068574d3 | ||
|
|
61d77278f6 | ||
|
|
094d24f82e | ||
|
|
8375eb5a36 | ||
|
|
f2a9e1f993 | ||
|
|
318a0205b0 | ||
|
|
f46c87a40d | ||
|
|
e0b9bfdb73 | ||
|
|
180869ecff | ||
|
|
b9ceb008ba | ||
|
|
3118183bd8 | ||
|
|
45b0a30155 | ||
|
|
5169496cb6 | ||
|
|
c1b3c15034 | ||
|
|
bd26b2d596 | ||
|
|
6cd38e4278 | ||
|
|
aa077b4bec |
No files matched your search
Generated
+34
-15
@@ -497,7 +497,7 @@ dependencies = [
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn 2.0.119",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -991,7 +991,6 @@ dependencies = [
|
||||
"figment",
|
||||
"futures",
|
||||
"governor",
|
||||
"hardened_malloc-rs",
|
||||
"http",
|
||||
"http-body-util",
|
||||
"hyper-util",
|
||||
@@ -999,8 +998,10 @@ dependencies = [
|
||||
"lettre",
|
||||
"libc",
|
||||
"libloading 0.9.1",
|
||||
"libmimalloc-sys",
|
||||
"lock_api 0.5.0",
|
||||
"maplit",
|
||||
"mimalloc",
|
||||
"nix",
|
||||
"num-traits",
|
||||
"openidconnect",
|
||||
@@ -1552,6 +1553,12 @@ dependencies = [
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cty"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
|
||||
|
||||
[[package]]
|
||||
name = "curve25519-dalek"
|
||||
version = "5.0.0"
|
||||
@@ -2395,12 +2402,6 @@ dependencies = [
|
||||
"tokio-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hardened_malloc-rs"
|
||||
version = "0.1.2+12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "647deb1583b14d160f85f3ff626f20b6edd366e3852c9843b06077388f794cb6"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
@@ -3256,6 +3257,16 @@ version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
||||
|
||||
[[package]]
|
||||
name = "libmimalloc-sys"
|
||||
version = "0.1.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cty",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.1.32"
|
||||
@@ -3429,6 +3440,15 @@ dependencies = [
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mimalloc"
|
||||
version = "0.1.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862"
|
||||
dependencies = [
|
||||
"libmimalloc-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.18"
|
||||
@@ -3982,8 +4002,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "opentelemetry-instrumentation-tower"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e7006f3b1853d315462a7237c81eec3d7adfa5b70975a02b19e92d045bc22d7"
|
||||
source = "git+https://github.com/open-telemetry/opentelemetry-rust-contrib?rev=6bbbc337aab0bcf10d7799c3e5b5ced75920491a#6bbbc337aab0bcf10d7799c3e5b5ced75920491a"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"http",
|
||||
@@ -5189,7 +5208,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rust-librocksdb-sys"
|
||||
version = "0.49.0+11.12.0"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=6021299f3e0e9455dc3f2e39c65e1dc217be8903#6021299f3e0e9455dc3f2e39c65e1dc217be8903"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=85ded20348e3dab902c239967075795e9c6d101b#85ded20348e3dab902c239967075795e9c6d101b"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"bzip2-sys",
|
||||
@@ -5207,7 +5226,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rust-rocksdb"
|
||||
version = "0.54.0"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=6021299f3e0e9455dc3f2e39c65e1dc217be8903#6021299f3e0e9455dc3f2e39c65e1dc217be8903"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=85ded20348e3dab902c239967075795e9c6d101b#85ded20348e3dab902c239967075795e9c6d101b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"parking_lot",
|
||||
@@ -6228,7 +6247,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tikv-jemalloc-ctl"
|
||||
version = "0.7.0"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=ac4d4861b335b199f812807996e8c9166961041a#ac4d4861b335b199f812807996e8c9166961041a"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=46e7821917b06636cdb5b203d312799970eaea92#46e7821917b06636cdb5b203d312799970eaea92"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"tikv-jemalloc-sys",
|
||||
@@ -6237,7 +6256,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tikv-jemalloc-sys"
|
||||
version = "0.7.0+5.4.0-0-g7a34f18502e7b222724097cdcd499b437d189acc"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=ac4d4861b335b199f812807996e8c9166961041a#ac4d4861b335b199f812807996e8c9166961041a"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=46e7821917b06636cdb5b203d312799970eaea92#46e7821917b06636cdb5b203d312799970eaea92"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
@@ -6246,7 +6265,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tikv-jemallocator"
|
||||
version = "0.7.0"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=ac4d4861b335b199f812807996e8c9166961041a#ac4d4861b335b199f812807996e8c9166961041a"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=46e7821917b06636cdb5b203d312799970eaea92#46e7821917b06636cdb5b203d312799970eaea92"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"tikv-jemalloc-sys",
|
||||
|
||||
+14
-14
@@ -407,7 +407,7 @@ features = [
|
||||
|
||||
[workspace.dependencies.rust-rocksdb]
|
||||
git = "https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1"
|
||||
rev = "6021299f3e0e9455dc3f2e39c65e1dc217be8903"
|
||||
rev = "85ded20348e3dab902c239967075795e9c6d101b"
|
||||
default-features = false
|
||||
features = [
|
||||
"multi-threaded-cf",
|
||||
@@ -435,7 +435,8 @@ features = ["reqwest"]
|
||||
version = "0.33.1"
|
||||
|
||||
[workspace.dependencies.opentelemetry-instrumentation-tower]
|
||||
version = "0.19.0"
|
||||
git = "https://github.com/open-telemetry/opentelemetry-rust-contrib"
|
||||
rev = "6bbbc337aab0bcf10d7799c3e5b5ced75920491a"
|
||||
default-features = false
|
||||
features = ["axum"]
|
||||
|
||||
@@ -490,7 +491,7 @@ version = "0.49.5"
|
||||
# jemalloc usage
|
||||
[workspace.dependencies.tikv-jemalloc-sys]
|
||||
git = "https://forgejo.ellis.link/continuwuation/jemallocator"
|
||||
rev = "ac4d4861b335b199f812807996e8c9166961041a"
|
||||
rev = "46e7821917b06636cdb5b203d312799970eaea92"
|
||||
default-features = false
|
||||
features = [
|
||||
"background_threads_runtime_support",
|
||||
@@ -498,7 +499,7 @@ features = [
|
||||
]
|
||||
[workspace.dependencies.tikv-jemallocator]
|
||||
git = "https://forgejo.ellis.link/continuwuation/jemallocator"
|
||||
rev = "ac4d4861b335b199f812807996e8c9166961041a"
|
||||
rev = "46e7821917b06636cdb5b203d312799970eaea92"
|
||||
default-features = false
|
||||
features = [
|
||||
"background_threads_runtime_support",
|
||||
@@ -506,7 +507,7 @@ features = [
|
||||
]
|
||||
[workspace.dependencies.tikv-jemalloc-ctl]
|
||||
git = "https://forgejo.ellis.link/continuwuation/jemallocator"
|
||||
rev = "ac4d4861b335b199f812807996e8c9166961041a"
|
||||
rev = "46e7821917b06636cdb5b203d312799970eaea92"
|
||||
default-features = false
|
||||
features = ["use_std"]
|
||||
|
||||
@@ -522,15 +523,6 @@ features = ["resource"]
|
||||
version = "0.5.0"
|
||||
default-features = false
|
||||
|
||||
[workspace.dependencies.hardened_malloc-rs]
|
||||
version = "0.1.2"
|
||||
default-features = false
|
||||
features = [
|
||||
"static",
|
||||
"gcc",
|
||||
"light",
|
||||
]
|
||||
|
||||
[workspace.dependencies.rustyline-async]
|
||||
version = "0.4.9"
|
||||
default-features = false
|
||||
@@ -610,6 +602,14 @@ features = ["unstable-msc4188"]
|
||||
[workspace.dependencies.serde_urlencoded]
|
||||
version = "0.7.1"
|
||||
|
||||
[workspace.dependencies.mimalloc]
|
||||
version = "0.1.52"
|
||||
features = ["extended"]
|
||||
|
||||
[workspace.dependencies.libmimalloc-sys]
|
||||
version = "0.1.49"
|
||||
features = ["extended"]
|
||||
|
||||
#
|
||||
# Patches
|
||||
#
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Fixed Prometheus accounting for in-flight requests, federation PDU lag, latency buckets, and thumbnail sizes. Contributed by @eleboucher.
|
||||
@@ -0,0 +1 @@
|
||||
The former configuration alias `allow_check_for_updates` is now explicitly deprecated in favor of `allow_announcements_check`. Additionally, `request_ip_source` is now deprecated in favor of `accepted_ip_sources`.
|
||||
@@ -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.
|
||||
@@ -0,0 +1 @@
|
||||
Dropped support for `hardened_malloc` and add support for `mimalloc` instead. Contributed by @nex and @jade.
|
||||
@@ -0,0 +1 @@
|
||||
Fix soundness and correctness issues in the jemalloc interface, improving performance. Contributed by @Jade
|
||||
@@ -0,0 +1 @@
|
||||
Modernised the room knocking helper functions to make them match the behaviour of our room join helpers, which are safer and more efficient. This also fixes a bug that caused an error when knocking on rooms not local to the server. Contributed by @nex.
|
||||
@@ -412,7 +412,7 @@
|
||||
# env: CONTINUWUITY_IP_LOOKUP_STRATEGY
|
||||
#ip_lookup_strategy = 5
|
||||
|
||||
# The preferred source to use for getting the real client IP.
|
||||
# DEPRECATED: The preferred source to use for getting the real client IP.
|
||||
#
|
||||
# Takes any of the following options:
|
||||
#
|
||||
@@ -431,9 +431,10 @@
|
||||
# to set this header" check; if the header selected is present, it is
|
||||
# used.
|
||||
#
|
||||
# Ignored if `accepted_ip_sources` is set.
|
||||
# Ignored if `accepted_ip_sources` is set. `accepted_ip_sources` is
|
||||
# the preferred alternative.
|
||||
#
|
||||
# If not set set, `direct` is used. Additionally, `direct` is used
|
||||
# If not set, `direct` is used. Additionally, `direct` is used
|
||||
# as a fallback if the chosen header is not found.
|
||||
#
|
||||
# env: CONTINUWUITY_REQUEST_IP_SOURCE
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ EOF
|
||||
|
||||
# Developer tool versions
|
||||
# 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
|
||||
ENV CARGO_SBOM_VERSION=0.9.1
|
||||
# renovate: datasource=crate depName=lddtree
|
||||
|
||||
@@ -18,7 +18,7 @@ RUN --mount=type=cache,target=/etc/apk/cache apk add \
|
||||
|
||||
# Developer tool versions
|
||||
# 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
|
||||
ENV CARGO_SBOM_VERSION=0.9.1
|
||||
# renovate: datasource=crate depName=lddtree
|
||||
|
||||
@@ -84,8 +84,9 @@ All forked dependencies are maintained under the
|
||||
- [rocksdb][continuwuation-rocksdb] - Fork of [facebook/rocksdb][rocksdb] via
|
||||
[`@zaidoon1`][8] with liburing build fixes and GCC debug build fixes
|
||||
- [jemallocator][continuwuation-jemallocator] - Fork of
|
||||
[tikv/jemallocator][jemallocator] fixing musl builds, suspicious code, and
|
||||
adding support for redzones in Valgrind
|
||||
[tikv/jemallocator][jemallocator] fixing musl builds and using jemalloc's
|
||||
`*x` APIs consistently in `GlobalAlloc` to avoid interposer/Valgrind
|
||||
mismatches
|
||||
- [rustyline-async][continuwuation-rustyline-async] - Fork of
|
||||
[zyansheep/rustyline-async][rustyline-async] with tab completion callback and
|
||||
`CTRL+\` signal quit event for Continuwuity console CLI
|
||||
|
||||
@@ -82,6 +82,7 @@ Names below are as they appear in Prometheus. OTLP uses the dotted OpenTelemetry
|
||||
| `continuwuity_database_block_cache_bytes` | gauge | `column` | RocksDB block cache usage |
|
||||
| `continuwuity_cache_entries` | gauge | `name` | Entries in the auth chain and state info caches |
|
||||
| `continuwuity_jemalloc_memory_bytes` | gauge | `kind` | jemalloc statistics, only with the `jemalloc_stats` feature |
|
||||
| `continuwuity_mimalloc_memory_bytes` | gauge | `kind` | mimalloc statistics, only with the `mimalloc` feature |
|
||||
| `process_uptime_seconds` | gauge | | Time since the server started |
|
||||
| `process_cpu_time_seconds_total` | counter | `cpu_mode` | CPU time used by the process |
|
||||
| `process_memory_usage_bytes` | gauge | | Resident memory (Linux) |
|
||||
|
||||
@@ -302,7 +302,7 @@
|
||||
"type": "prometheus",
|
||||
"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": "",
|
||||
"refId": "A",
|
||||
"range": true
|
||||
@@ -496,7 +496,7 @@
|
||||
"type": "prometheus",
|
||||
"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",
|
||||
"refId": "A",
|
||||
"range": true
|
||||
@@ -506,7 +506,7 @@
|
||||
"type": "prometheus",
|
||||
"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",
|
||||
"refId": "B",
|
||||
"range": true
|
||||
@@ -516,7 +516,7 @@
|
||||
"type": "prometheus",
|
||||
"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",
|
||||
"refId": "C",
|
||||
"range": true
|
||||
@@ -1228,7 +1228,7 @@
|
||||
{
|
||||
"type": "timeseries",
|
||||
"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,
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
|
||||
Generated
+131
-104
@@ -16,21 +16,21 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/core": {
|
||||
"version": "1.11.3",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.3.tgz",
|
||||
"integrity": "sha512-zLpS5asjEb7lq8jYLq37N6XKaE41DIexlY1rF/z4/tIl3wo13Sqm28fRyfIsKZD+NZ8mM5RoKkpW/rBcuoSZSg==",
|
||||
"version": "2.0.0-beta.3",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-2.0.0-beta.3.tgz",
|
||||
"integrity": "sha512-KA+gOBtbifRATmUa/Gpf5C2B2EJ0r4brHUT3XSgACeHREcuiObXH56xd+B3fFsEFbUT04VBEe6MuZiCtMp0tQg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/wasi-threads": "1.2.3",
|
||||
"@emnapi/wasi-threads": "2.2.0",
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/runtime": {
|
||||
"version": "1.11.3",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz",
|
||||
"integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==",
|
||||
"version": "2.0.0-beta.3",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-2.0.0-beta.3.tgz",
|
||||
"integrity": "sha512-ayb/PyyLzpwRyFVxeC0uoEHu59QlB1iWGcGsOpXQcaB/Dc+uGfBmNmpCHp3HmTT0t8lSsMmg3j7+tdJW/TlHjQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
@@ -39,9 +39,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/wasi-threads": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.3.tgz",
|
||||
"integrity": "sha512-ELEBe8PsLvvJ6QMr0zLt8ffvOHW/dc1m3CEzNMg7aJUv3bMaoDtw2TXyDAwkYBuroxxuHEwhRTLJSe5sya547g==",
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-2.2.0.tgz",
|
||||
"integrity": "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
@@ -106,33 +106,36 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/wasm-runtime": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.6.tgz",
|
||||
"integrity": "sha512-ZLv/JdUfkvOy9eCnnBaGfiO+XimbjebAeO+MRQqD/B+FR1tnRN0tpKSJHRbE8sFfS6aqsXZ67TQjfwfsxULVbg==",
|
||||
"version": "1.2.7",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.7.tgz",
|
||||
"integrity": "sha512-zJccwplOAbgfZju95IUHazLnx9RAPtPN2YGJXI6UbrgeaR9QfPjGrQL6ERkSAtnVCA4Q+83ApGyaX5zdpCaKkQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@tybys/wasm-util": "^0.10.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || >=23.5.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@emnapi/core": "^1.7.1",
|
||||
"@emnapi/runtime": "^1.7.1"
|
||||
"@emnapi/core": "^1.7.1 || 2.0.0-beta.2 || 2.0.0-beta.3",
|
||||
"@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2 || 2.0.0-beta.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@rsbuild/core": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rsbuild/core/-/core-2.3.1.tgz",
|
||||
"integrity": "sha512-dv5tL7djb8ex5z4sqnDmUbd5PnGNr/CXuFfiMD4RkUsF1JEZZkGH8lc+QW4fqYQIHM7RTvcMUakgvwVU/O9WMw==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rsbuild/core/-/core-2.3.3.tgz",
|
||||
"integrity": "sha512-IdbBXZrIY16RxnQduXRrsRBQtJ/X7JkYESrk6D46WA918wrckYTBxE09vHvDxR+3JoCLE02vOm2NPBNxqaUw5A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rspack/core": "~2.3.1",
|
||||
"@swc/helpers": "^0.5.23"
|
||||
"@rspack/core": "~2.3.3",
|
||||
"@swc/helpers": "^0.5.24"
|
||||
},
|
||||
"bin": {
|
||||
"rsbuild": "bin/rsbuild.js"
|
||||
@@ -169,32 +172,32 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspack/binding": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding/-/binding-2.3.1.tgz",
|
||||
"integrity": "sha512-pfCJGBFNK2tnNnoDP6ZoTbOjxbKr1U2eGFDJ8bIuZQai4FBNhWQlKFmNup+X5K935XYRulZBomIBAL6GL6W2YQ==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding/-/binding-2.3.3.tgz",
|
||||
"integrity": "sha512-wwF++36a3rqYi0G9zj+rUavn/GIMzbzXehelGS1jkYeKPHyPXrVYwRHqwEKNKMD9z+FdW4YJKQcfFkPlHEiwUg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optionalDependencies": {
|
||||
"@rspack/binding-darwin-arm64": "2.3.1",
|
||||
"@rspack/binding-darwin-x64": "2.3.1",
|
||||
"@rspack/binding-linux-arm64-gnu": "2.3.1",
|
||||
"@rspack/binding-linux-arm64-musl": "2.3.1",
|
||||
"@rspack/binding-linux-ppc64-gnu": "2.3.1",
|
||||
"@rspack/binding-linux-riscv64-gnu": "2.3.1",
|
||||
"@rspack/binding-linux-riscv64-musl": "2.3.1",
|
||||
"@rspack/binding-linux-s390x-gnu": "2.3.1",
|
||||
"@rspack/binding-linux-x64-gnu": "2.3.1",
|
||||
"@rspack/binding-linux-x64-musl": "2.3.1",
|
||||
"@rspack/binding-wasm32-wasi": "2.3.1",
|
||||
"@rspack/binding-win32-arm64-msvc": "2.3.1",
|
||||
"@rspack/binding-win32-ia32-msvc": "2.3.1",
|
||||
"@rspack/binding-win32-x64-msvc": "2.3.1"
|
||||
"@rspack/binding-darwin-arm64": "2.3.3",
|
||||
"@rspack/binding-darwin-x64": "2.3.3",
|
||||
"@rspack/binding-linux-arm64-gnu": "2.3.3",
|
||||
"@rspack/binding-linux-arm64-musl": "2.3.3",
|
||||
"@rspack/binding-linux-ppc64-gnu": "2.3.3",
|
||||
"@rspack/binding-linux-riscv64-gnu": "2.3.3",
|
||||
"@rspack/binding-linux-riscv64-musl": "2.3.3",
|
||||
"@rspack/binding-linux-s390x-gnu": "2.3.3",
|
||||
"@rspack/binding-linux-x64-gnu": "2.3.3",
|
||||
"@rspack/binding-linux-x64-musl": "2.3.3",
|
||||
"@rspack/binding-wasm32-wasi": "2.3.3",
|
||||
"@rspack/binding-win32-arm64-msvc": "2.3.3",
|
||||
"@rspack/binding-win32-ia32-msvc": "2.3.3",
|
||||
"@rspack/binding-win32-x64-msvc": "2.3.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@rspack/binding-darwin-arm64": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-arm64/-/binding-darwin-arm64-2.3.1.tgz",
|
||||
"integrity": "sha512-koLyL2r8PUcLD0StjuZ/n5XM6GJ0C8dzJN0IuIV9d7nQcibJxwjjSAWEPGVz6bm8WuzypvuVKNoa1+GGAHeMQA==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-arm64/-/binding-darwin-arm64-2.3.3.tgz",
|
||||
"integrity": "sha512-G9WcBOP/6ZWeqTM/G0/rkJRY4DWmYQvk2untzcpj92uO12tqjZ9BSMgtBFvwElwagfQBkX8PPutkAZgtnlAoWA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -206,9 +209,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-darwin-x64": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-x64/-/binding-darwin-x64-2.3.1.tgz",
|
||||
"integrity": "sha512-YK39JLiu1YC6+3BMxkP7e848pHD7e2T/0OSNogDi7whfiZNg95wa9Ncd7I5ppAf0nhmV+FNew/sCBIFp5h67Jw==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-x64/-/binding-darwin-x64-2.3.3.tgz",
|
||||
"integrity": "sha512-6agI5XDoihay+84vzZgIwwpQQ3xBWbe2HTWBRc0n42LzynIj9h7Qv8CJzf1gSDV1Ts0jzDgAJCYUFJ6Ya5F6MA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -220,13 +223,16 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-arm64-gnu": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-2.3.1.tgz",
|
||||
"integrity": "sha512-Q+RCA/KM2tn6m6R5U4lktXDs5cCRm3SyleQk86iqqUFX7wKzVRUvr5BTsreg6K9of3gpYmQ6+g1PGT5cwo0rLA==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-2.3.3.tgz",
|
||||
"integrity": "sha512-VdjK1mDq+GBexd041lmWBFmAvcWIZy7kepTJbJgxLeHYYOnI3KmBG15kemhlK0pBySa+bePX7p2w8uYtl1HsCA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -234,13 +240,16 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-arm64-musl": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-musl/-/binding-linux-arm64-musl-2.3.1.tgz",
|
||||
"integrity": "sha512-He+muVDON1fohGtdYamh3zHVwf6/E6fZu/+iEAkxjclE0P94bsCfYVcZW/a4/l1tJ2zvLZtB4jD7Qr6r4vG/WA==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-musl/-/binding-linux-arm64-musl-2.3.3.tgz",
|
||||
"integrity": "sha512-xF4Wy4XwGjC3m13tFm1q9p9Qpm31qrk6f5zEMPZC31UVabb+2jrgTI1pfZ8IRuo9x/Qw9s+Zq3hyDbtJvvD8Pg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -248,13 +257,16 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-ppc64-gnu": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-2.3.1.tgz",
|
||||
"integrity": "sha512-blIZUgyPt4FcSHkZL6sJ2xbzc7ACgDeU49An4mXLSebwdgnlhTzxeSFnh2VeJDlGza8CUaZYB/zS/6oZ2kCDcw==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-2.3.3.tgz",
|
||||
"integrity": "sha512-jVmn+LpF44D4FdZyT91rlT/tPMdHIfPfQTgVzwPB5nDICp4b57SFjVBApuAPIxnLT1pKLkv/LIcdvGSdAeX12w==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -262,13 +274,16 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-riscv64-gnu": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-gnu/-/binding-linux-riscv64-gnu-2.3.1.tgz",
|
||||
"integrity": "sha512-3FtW2DUFmXxhBORUA3zSc+ot4d6R/1/U6z/48TDN4jeIYDUG9VqYBF6LUohX4vBY6IP0DCyXb2N9WayD/9QXoA==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-gnu/-/binding-linux-riscv64-gnu-2.3.3.tgz",
|
||||
"integrity": "sha512-JcQJm8M634jkbG6zJ3TfziKYsCINEAh3FwKuxLljvBgGDEupBxPuB0n2bXBIUeI8P9C33B45IYX6BwWYXll/zw==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -276,13 +291,16 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-riscv64-musl": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-musl/-/binding-linux-riscv64-musl-2.3.1.tgz",
|
||||
"integrity": "sha512-+5qNgdNdXzp/K8f8BjgJ3m7tcbBKPENN7WPDfBcSHvWb5GF4+o/pbrX26c0+LEugo0bYUOAoitBNd94AwcNvpA==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-musl/-/binding-linux-riscv64-musl-2.3.3.tgz",
|
||||
"integrity": "sha512-YMIOS7rFvCDnpeyxoVEVbM7U/TwcC2VDtN3Oiq9BenRsNTEvk0imINhuVRFanh15+wkiQHk9h0b+pzcggYLAsA==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -290,13 +308,16 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-s390x-gnu": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-2.3.1.tgz",
|
||||
"integrity": "sha512-yNcg/y1+MV0wZ984CVU4d1HAYYwMcDPXoQO0xynU+K5YuBxPWALHOxuRRCKCcykBdL1GIEshAIewEFrsW/cmJg==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-2.3.3.tgz",
|
||||
"integrity": "sha512-tHGtIG6GGHsk2KvSleQp/BrVqiGdjDsLJuMKR7hE7W1uJW6WDJ+a+Z23Rk5kHXh5BjeFLjXxcufGuokvmLmTag==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -304,13 +325,16 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-x64-gnu": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-gnu/-/binding-linux-x64-gnu-2.3.1.tgz",
|
||||
"integrity": "sha512-ffclKBuH8wwimOBd6xGUxrBfVKKY5Ow4E7OFdHZeg4xffm2O8auGszmOgvFu1eoDoOYHaVJn+cEV6UD0KwZk8A==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-gnu/-/binding-linux-x64-gnu-2.3.3.tgz",
|
||||
"integrity": "sha512-spe8SjywfO+dD7Sk+vIpPaOXf56wstrgeuztfJdiI9zTeQmf/lhdaNUUSUAXlGIaLjrN/PhV8i5kbQ7VaAkenw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -318,13 +342,16 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-x64-musl": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-musl/-/binding-linux-x64-musl-2.3.1.tgz",
|
||||
"integrity": "sha512-qcDwwuyxR7TMtrW+r5Y9RIW25boXd1Ip/9jz04jhdq/OiU/Am7rCP2X90CH8sWdzovIF9UNmsGjY4KklR0F2Mg==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-musl/-/binding-linux-x64-musl-2.3.3.tgz",
|
||||
"integrity": "sha512-4E4OJodrmsS52zkSAWShG/F07etr0OG4oSrIN+/2BBgc0qR2wwu2T+rAs308IL3lbywlS+J+cynrRcsSFMD+Kg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -332,9 +359,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-wasm32-wasi": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-wasm32-wasi/-/binding-wasm32-wasi-2.3.1.tgz",
|
||||
"integrity": "sha512-3dr6zjFaCK3A920ftCriSJkiRhEfhHtat7LtBdj6g0mcV5Rt+iealmli0vjeAvD0UdpE1u8EKWlfw82JLgFLSQ==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-wasm32-wasi/-/binding-wasm32-wasi-2.3.3.tgz",
|
||||
"integrity": "sha512-AhlsPjW31TGP8N+J7OmbCPaamARUl+OQNiT3xo0PL5Dz5oMm+bEfYLostpehKyy8MNDrmJcY97M9pDb5MDMA0w==",
|
||||
"cpu": [
|
||||
"wasm32"
|
||||
],
|
||||
@@ -342,15 +369,15 @@
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/core": "1.11.3",
|
||||
"@emnapi/runtime": "1.11.3",
|
||||
"@napi-rs/wasm-runtime": "1.1.6"
|
||||
"@emnapi/core": "2.0.0-beta.3",
|
||||
"@emnapi/runtime": "2.0.0-beta.3",
|
||||
"@napi-rs/wasm-runtime": "1.2.7"
|
||||
}
|
||||
},
|
||||
"node_modules/@rspack/binding-win32-arm64-msvc": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-2.3.1.tgz",
|
||||
"integrity": "sha512-AZbuLPylt1xvWssN93AsirbYs3WgfcrA8tMsqHmVJIHahLu9E+JPKZ3Gmsw6IYEZk3EfnV3ujQzeQ1/VfF0Vsw==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-2.3.3.tgz",
|
||||
"integrity": "sha512-Zqbj7GBPtkJ8GlUKAjFgvmOxKkQwjfS3XfjwGBcmoIAUb4IxUsmMqvi+gfKrvI45SjYVFZaJnTpOJw6GL79K+Q==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -362,9 +389,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-win32-ia32-msvc": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-2.3.1.tgz",
|
||||
"integrity": "sha512-R5NVU68TePZcgRdYUzrQX9YFNxmcyXZEPwaPv40AAgsqNyacG3iRaYVmV79jt3rWYfa0QJaqvRLUchDe2SZ6zQ==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-2.3.3.tgz",
|
||||
"integrity": "sha512-sJJmbrdzH6kI48mCsUu5a2+BzEktLmHrHUmWGkAPAi0zhi4anA7sOdS1+uERbkkd/XAzs0bdn3JXyT2djY+3IA==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
@@ -376,9 +403,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-win32-x64-msvc": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-x64-msvc/-/binding-win32-x64-msvc-2.3.1.tgz",
|
||||
"integrity": "sha512-5T9DYjNPQpLbrNXjCssGd2B6xMQPlc3LxVOKHGUA1O0GV+88vBkTXAcryJ+Fo+yVEMPCzp4VvwBMGAVDpCjcSA==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-x64-msvc/-/binding-win32-x64-msvc-2.3.3.tgz",
|
||||
"integrity": "sha512-1r3wxV1pBNykqpbEbZWqcrZd13PKLq0e7Ku6qv8IGKKeftuf3RUxTkeM5AzppGMGEIA9sw8mRdN7NvEXxqLLxw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -390,13 +417,13 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/core": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/core/-/core-2.3.1.tgz",
|
||||
"integrity": "sha512-9BWfaiEJLgLK9U53Q4WVruBZ19Mu/XWHXHEu0UFla4lUtH8Z+/ET2m044tiqbtyIgqQyG58fMrxHeVIAiXMXHg==",
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/core/-/core-2.3.3.tgz",
|
||||
"integrity": "sha512-stAYr0SXf+ZFXFsWTv+Ljxoj/nQs2p7gX9V1kBwlO2IXlRAAhabLONYibT3ZeEGybx3kowrs7uJkcOQsuHgghw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rspack/binding": "2.3.1"
|
||||
"@rspack/binding": "2.3.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
@@ -431,17 +458,17 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/core": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.3.tgz",
|
||||
"integrity": "sha512-qKa5c7zHO8cmhxkReURd3dN/ZRfHYnEztdIQ9hMuolaNzhSYo2A36XErUvLvbMf2EUM2AxfPYRQv+4Crfeq6pw==",
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.4.tgz",
|
||||
"integrity": "sha512-7OmP7ABDgQLSpVfpBHfpjqu4H3PGBGMyhLxF1crPQ48Q6MIWAVu77nw7cONn8AZa9GoVq0N/DoE3GEtgZzlu6w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@mdx-js/mdx": "^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",
|
||||
"@rspress/shared": "2.1.3",
|
||||
"@rspress/shared": "2.1.4",
|
||||
"@shikijs/rehype": "^4.2.0",
|
||||
"@shikijs/transformers": "^4.2.0",
|
||||
"@types/mdast": "^4.0.4",
|
||||
@@ -485,9 +512,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/plugin-client-redirects": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.1.3.tgz",
|
||||
"integrity": "sha512-iEqJ8qEFuUxGKRVaS/WMyFi8FiJlogdcEHbGK/UjY8+8Hg8r8aSv4YihmNh3Ev/uIW21hrC8aXMEgVo0H51Q+g==",
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.1.4.tgz",
|
||||
"integrity": "sha512-6/g+Mr8lslqiFzlMBouex8TLm6PlQK6cmZ71Yfv82+Uxcrb+LaFAFiPbq2G7gToXBQUoECM4D/7nSLAfeOhnEQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -498,9 +525,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/plugin-sitemap": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.3.tgz",
|
||||
"integrity": "sha512-Fqo7/4PfQK1ecHUFoUDMrR/E+Hcu+kIohxSs8QabflMy3dqk+M3ZqzJDOHpVYB+HLLGwKiqkPLT4BK+W93clkw==",
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.4.tgz",
|
||||
"integrity": "sha512-TObDTXgBKFAHEWEth47aehQSYtFfpIkqM4w14a0hUbPLkbu2AZ2cKnMzFTKK+W6I/3LN54scvfGYTL5CPQsDXw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -511,13 +538,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/shared": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.3.tgz",
|
||||
"integrity": "sha512-VwJ7kgsTWVqHzSXQVHIUCsdMparmq9b/IDmTa3a6jMPl1zmm5Qg9M0eP4j8JXWoIS9n19XtCkQcZmMTFOPRy3A==",
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.4.tgz",
|
||||
"integrity": "sha512-SuQyVKn9xcQwkzfl+4bPBzX10gxbhCs9UupqSoPtxvyr9pMgSbXnlo3gxTPZXLzk5HUqZZ6tlIju25PVCEtYWA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rsbuild/core": "^2.2.14",
|
||||
"@rsbuild/core": "^2.3.3",
|
||||
"@shikijs/rehype": "^4.2.0",
|
||||
"@types/react": "^19.3.0",
|
||||
"mdast-util-mdx-jsx": "^3.2.1",
|
||||
@@ -672,9 +699,9 @@
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@tybys/wasm-util": {
|
||||
"version": "0.10.4",
|
||||
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz",
|
||||
"integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==",
|
||||
"version": "0.10.5",
|
||||
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.5.tgz",
|
||||
"integrity": "sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
|
||||
@@ -1007,7 +1007,7 @@ impl crate::Context<'_> {
|
||||
pub(super) async fn memory_stats(&self, opts: Option<String>) -> Result {
|
||||
const OPTS: &str = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
let opts: String = OPTS
|
||||
let mut mapped_opts: String = OPTS
|
||||
.chars()
|
||||
.filter(|&c| {
|
||||
let allow_any = opts.as_ref().is_some_and(|opts| opts == "*");
|
||||
@@ -1018,7 +1018,11 @@ impl crate::Context<'_> {
|
||||
})
|
||||
.collect();
|
||||
|
||||
let stats = conduwuit::alloc::memory_stats(&opts).unwrap_or_default();
|
||||
if opts.as_ref().is_some_and(|opts| opts.contains('J')) {
|
||||
mapped_opts.push('J');
|
||||
}
|
||||
|
||||
let stats = conduwuit::alloc::memory_stats(&mapped_opts).unwrap_or_default();
|
||||
|
||||
self.write_str("```\n").await?;
|
||||
self.write_str(&stats).await?;
|
||||
|
||||
@@ -192,7 +192,8 @@ pub enum DebugCommand {
|
||||
///
|
||||
/// Optional argument is a character mask (a sequence of characters in any
|
||||
/// order) which enable additional extended statistics. Known characters are
|
||||
/// "abdeglmx". For convenience, a '*' will enable everything.
|
||||
/// "abdeglmx" and 'J' for JSON output. For convenience, a '*' will enable
|
||||
/// everything.
|
||||
MemoryStats {
|
||||
opts: Option<String>,
|
||||
},
|
||||
|
||||
+221
-416
@@ -1,9 +1,10 @@
|
||||
use std::{borrow::Borrow, collections::HashMap, sync::Arc};
|
||||
use std::collections::{HashMap, hash_map::Entry};
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Result, debug, debug_info, debug_warn, err, info,
|
||||
Err, EventTypeExt, Result, debug, debug_warn, err, info,
|
||||
matrix::{
|
||||
StateKey,
|
||||
event::gen_event_id,
|
||||
pdu::{PartialPdu, PduEvent},
|
||||
},
|
||||
@@ -15,24 +16,23 @@ use conduwuit::{
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use ruma::{
|
||||
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName,
|
||||
OwnedUserId, RoomId, UserId,
|
||||
api::{client::knock::knock_room, federation},
|
||||
OwnedUserId, RoomId, RoomVersionId, UserId,
|
||||
api::{
|
||||
client::knock::knock_room,
|
||||
error::{ErrorKind, IncompatibleRoomVersionErrorData},
|
||||
federation,
|
||||
federation::membership::RawStrippedState,
|
||||
},
|
||||
canonical_json::to_canonical_value,
|
||||
events::{
|
||||
StateEventType,
|
||||
room::{
|
||||
join_rules::{AllowRule, JoinRule},
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
room::member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
room_version_rules::RoomVersionRules,
|
||||
};
|
||||
use service::{
|
||||
Services,
|
||||
rooms::{
|
||||
membership::validate_remote_member_event_stub,
|
||||
state::RoomMutexGuard,
|
||||
state_compressor::{CompressedState, HashSetCompressStateEvent},
|
||||
},
|
||||
rooms::{membership::validate_remote_member_event_stub, state::RoomMutexGuard},
|
||||
};
|
||||
|
||||
use super::banned_room_check;
|
||||
@@ -187,121 +187,24 @@ async fn knock_room_by_id_helper(
|
||||
}
|
||||
}
|
||||
|
||||
// For knock_restricted rooms, check if the user meets the restricted
|
||||
// conditions If they do, attempt to join instead of knock
|
||||
// This is not mentioned in the spec, but should be allowable (we're allowed
|
||||
// to auto-join invites to knocked rooms)
|
||||
let join_rule = services.rooms.state_accessor.get_join_rules(room_id).await;
|
||||
|
||||
if let JoinRule::KnockRestricted(restricted) = &join_rule {
|
||||
let restriction_rooms: Vec<_> = restricted
|
||||
.allow
|
||||
.iter()
|
||||
.filter_map(|a| match a {
|
||||
| AllowRule::RoomMembership(r) => Some(&r.room_id),
|
||||
| _ => None,
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Check if the user is in any of the allowed rooms
|
||||
let mut user_meets_restrictions = false;
|
||||
for restriction_room_id in &restriction_rooms {
|
||||
if services
|
||||
.rooms
|
||||
.state_cache
|
||||
.is_joined(sender_user, restriction_room_id)
|
||||
.await
|
||||
{
|
||||
user_meets_restrictions = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the user meets the restrictions, try joining instead
|
||||
if user_meets_restrictions {
|
||||
debug_info!(
|
||||
"{sender_user} meets the restricted criteria in knock_restricted room \
|
||||
{room_id}, attempting to join instead of knock"
|
||||
);
|
||||
// For this case, we need to drop the state lock and get a new one
|
||||
// in join_room_by_id_helper We need to release the lock here and
|
||||
// let join_room_by_id_helper acquire it again
|
||||
drop(state_lock);
|
||||
match services
|
||||
.rooms
|
||||
.membership
|
||||
.join_room(sender_user, room_id, reason.clone(), servers)
|
||||
.await
|
||||
{
|
||||
| Ok(_) => return Ok(knock_room::v3::Response::new(room_id.to_owned())),
|
||||
| Err(e) => {
|
||||
debug_warn!(
|
||||
"Failed to convert knock to join for {sender_user} in {room_id}: {e:?}"
|
||||
);
|
||||
// Get a new state lock for the remaining knock logic
|
||||
let new_state_lock = services.rooms.state.mutex.lock(room_id).await;
|
||||
|
||||
let server_in_room = services
|
||||
.rooms
|
||||
.state_cache
|
||||
.server_in_room(services.globals.server_name(), room_id)
|
||||
.await;
|
||||
|
||||
let local_knock = server_in_room
|
||||
|| servers.is_empty()
|
||||
|| (servers.len() == 1 && services.globals.server_is_ours(&servers[0]));
|
||||
|
||||
if local_knock {
|
||||
knock_room_helper_local(
|
||||
services,
|
||||
sender_user,
|
||||
room_id,
|
||||
reason,
|
||||
servers,
|
||||
new_state_lock,
|
||||
)
|
||||
.boxed()
|
||||
.await?;
|
||||
} else {
|
||||
knock_room_helper_remote(
|
||||
services,
|
||||
sender_user,
|
||||
room_id,
|
||||
reason,
|
||||
servers,
|
||||
new_state_lock,
|
||||
)
|
||||
.boxed()
|
||||
.await?;
|
||||
}
|
||||
|
||||
return Ok(knock_room::v3::Response::new(room_id.to_owned()));
|
||||
},
|
||||
}
|
||||
}
|
||||
} else if !matches!(join_rule, JoinRule::Knock | JoinRule::KnockRestricted(_)) {
|
||||
debug_warn!(
|
||||
"{sender_user} attempted to knock on room {room_id} but its join rule is \
|
||||
{join_rule:?}, not knock or knock_restricted"
|
||||
);
|
||||
}
|
||||
|
||||
let server_in_room = services
|
||||
.rooms
|
||||
.state_cache
|
||||
.server_in_room(services.globals.server_name(), room_id)
|
||||
.await;
|
||||
|
||||
let local_knock = server_in_room
|
||||
|| servers.is_empty()
|
||||
|| (servers.len() == 1 && services.globals.server_is_ours(&servers[0]));
|
||||
|
||||
if local_knock {
|
||||
knock_room_helper_local(services, sender_user, room_id, reason, servers, state_lock)
|
||||
if !server_in_room && !servers.iter().any(|sn| services.globals.server_is_ours(sn)) {
|
||||
return Err!(Request(NotFound(
|
||||
"Room {room_id} not found and no remote servers were provided to discover it"
|
||||
)));
|
||||
} else if server_in_room {
|
||||
// Local knocks can't fail unless the room is corrupted, so we don't
|
||||
// fall back to remote knocks like we do with remote joins.
|
||||
knock_room_helper_local(services, sender_user, room_id, reason, state_lock)
|
||||
.boxed()
|
||||
.await?;
|
||||
} else {
|
||||
knock_room_helper_remote(services, sender_user, room_id, reason, servers, state_lock)
|
||||
knock_room_helper_remote(services, sender_user, room_id, reason, servers)
|
||||
.boxed()
|
||||
.await?;
|
||||
}
|
||||
@@ -314,11 +217,8 @@ async fn knock_room_helper_local(
|
||||
sender_user: &UserId,
|
||||
room_id: &RoomId,
|
||||
reason: Option<String>,
|
||||
servers: &[OwnedServerName],
|
||||
state_lock: RoomMutexGuard,
|
||||
) -> Result {
|
||||
debug_info!("We can knock locally");
|
||||
|
||||
let room_version = services.rooms.state.get_room_version(room_id).await?;
|
||||
let room_version_rules = room_version
|
||||
.rules()
|
||||
@@ -333,8 +233,7 @@ async fn knock_room_helper_local(
|
||||
content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
||||
content.reason.clone_from(&reason.clone());
|
||||
|
||||
// Try normal knock first
|
||||
let Err(error) = services
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
@@ -344,129 +243,7 @@ async fn knock_room_helper_local(
|
||||
&state_lock,
|
||||
)
|
||||
.await
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
if servers.is_empty() || (servers.len() == 1 && services.globals.server_is_ours(&servers[0]))
|
||||
{
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
let (make_knock_response, remote_server) =
|
||||
make_knock_request(services, sender_user, room_id, servers).await?;
|
||||
|
||||
info!("make_knock finished");
|
||||
|
||||
let room_version = make_knock_response.room_version;
|
||||
let room_version_rules = room_version
|
||||
.rules()
|
||||
.expect("room version should have defined rules");
|
||||
|
||||
if !services.server.supported_room_version(&room_version) {
|
||||
return Err!(BadServerResponse("Remote room version {room_version} is not supported"));
|
||||
}
|
||||
|
||||
let mut knock_event_stub = serde_json::from_str::<CanonicalJsonObject>(
|
||||
make_knock_response.event.get(),
|
||||
)
|
||||
.map_err(|e| {
|
||||
err!(BadServerResponse("Invalid make_knock event json received from server: {e:?}"))
|
||||
})?;
|
||||
|
||||
validate_remote_member_event_stub(
|
||||
&MembershipState::Knock,
|
||||
sender_user,
|
||||
room_id,
|
||||
&knock_event_stub,
|
||||
)?;
|
||||
|
||||
knock_event_stub.insert(
|
||||
"origin".to_owned(),
|
||||
CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()),
|
||||
);
|
||||
knock_event_stub.insert(
|
||||
"origin_server_ts".to_owned(),
|
||||
CanonicalJsonValue::Integer(
|
||||
utils::millis_since_unix_epoch()
|
||||
.try_into()
|
||||
.expect("Timestamp is valid js_int value"),
|
||||
),
|
||||
);
|
||||
knock_event_stub.insert(
|
||||
"content".to_owned(),
|
||||
to_canonical_value(content).expect("event is valid, we just created it"),
|
||||
);
|
||||
|
||||
// In order to create a compatible ref hash (EventID) the `hashes` field
|
||||
// needs to be present
|
||||
services
|
||||
.server_keys
|
||||
.hash_and_sign_event(&mut knock_event_stub, &room_version_rules)?;
|
||||
|
||||
// Generate event id
|
||||
let event_id = gen_event_id(&knock_event_stub, &room_version_rules)?;
|
||||
|
||||
// Add event_id
|
||||
knock_event_stub
|
||||
.insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into()));
|
||||
|
||||
// It has enough fields to be called a proper event now
|
||||
let knock_event = knock_event_stub;
|
||||
|
||||
info!("Asking {remote_server} for send_knock in room {room_id}");
|
||||
let send_knock_request = federation::membership::create_knock_event::v1::Request::new(
|
||||
room_id.to_owned(),
|
||||
event_id.clone(),
|
||||
services
|
||||
.sending
|
||||
.convert_to_outgoing_federation_event(knock_event.clone())
|
||||
.await,
|
||||
);
|
||||
|
||||
services
|
||||
.sending
|
||||
.send_federation_request(&remote_server, send_knock_request)
|
||||
.await?;
|
||||
|
||||
info!("send_knock finished");
|
||||
|
||||
services
|
||||
.rooms
|
||||
.short
|
||||
.get_or_create_shortroomid(room_id)
|
||||
.await;
|
||||
|
||||
info!("Parsing knock event");
|
||||
|
||||
let parsed_knock_pdu = PduEvent::from_id_val(&event_id, knock_event.clone())
|
||||
.map_err(|e| err!(BadServerResponse("Invalid knock event PDU: {e:?}")))?;
|
||||
|
||||
info!("Updating membership locally to knock state with provided stripped state events");
|
||||
// TODO: this call does not appear to do anything because
|
||||
// `update_membership` doesn't call `mark_as_knock`. investigate further,
|
||||
// ideally with the aim of removing this call entirely -- Ginger thinks
|
||||
// `update_membership` should only be called from `force_state` and
|
||||
// `append_pdu`.
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.update_membership(room_id, sender_user, &parsed_knock_pdu, false)
|
||||
.await?;
|
||||
|
||||
info!("Appending room knock event locally");
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.progress_extremities(&parsed_knock_pdu)
|
||||
.await?;
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.append_pdu(&parsed_knock_pdu, knock_event, room_id)
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
async fn knock_room_helper_remote(
|
||||
@@ -475,16 +252,14 @@ async fn knock_room_helper_remote(
|
||||
room_id: &RoomId,
|
||||
reason: Option<String>,
|
||||
servers: &[OwnedServerName],
|
||||
state_lock: RoomMutexGuard,
|
||||
) -> Result {
|
||||
info!("Knocking {room_id} over federation.");
|
||||
info!(via=?servers, "Knocking on {room_id} over federation.");
|
||||
|
||||
let (make_knock_response, remote_server) =
|
||||
let (mut stub, room_version, remote_server) =
|
||||
make_knock_request(services, sender_user, room_id, servers).await?;
|
||||
|
||||
info!("make_knock finished");
|
||||
|
||||
let room_version = make_knock_response.room_version;
|
||||
let room_version_rules = room_version
|
||||
.rules()
|
||||
.expect("room version should have defined rules");
|
||||
@@ -493,16 +268,7 @@ async fn knock_room_helper_remote(
|
||||
return Err!(BadServerResponse("Remote room version {room_version} is not supported"));
|
||||
}
|
||||
|
||||
let mut knock_event_stub: CanonicalJsonObject =
|
||||
serde_json::from_str(make_knock_response.event.get()).map_err(|e| {
|
||||
err!(BadServerResponse("Invalid make_knock event json received from server: {e:?}"))
|
||||
})?;
|
||||
|
||||
knock_event_stub.insert(
|
||||
"origin".to_owned(),
|
||||
CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()),
|
||||
);
|
||||
knock_event_stub.insert(
|
||||
stub.insert(
|
||||
"origin_server_ts".to_owned(),
|
||||
CanonicalJsonValue::Integer(
|
||||
utils::millis_since_unix_epoch()
|
||||
@@ -516,7 +282,7 @@ async fn knock_room_helper_remote(
|
||||
knock_content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
||||
knock_content.reason = reason;
|
||||
|
||||
knock_event_stub.insert(
|
||||
stub.insert(
|
||||
"content".to_owned(),
|
||||
to_canonical_value(knock_content).expect("event is valid, we just created it"),
|
||||
);
|
||||
@@ -525,17 +291,15 @@ async fn knock_room_helper_remote(
|
||||
// needs to be present
|
||||
services
|
||||
.server_keys
|
||||
.hash_and_sign_event(&mut knock_event_stub, &room_version_rules)?;
|
||||
.hash_and_sign_event(&mut stub, &room_version_rules)?;
|
||||
|
||||
// Generate event id
|
||||
let event_id = gen_event_id(&knock_event_stub, &room_version_rules)?;
|
||||
let event_id = gen_event_id(&stub, &room_version_rules)?;
|
||||
|
||||
// Add event_id
|
||||
knock_event_stub
|
||||
.insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into()));
|
||||
|
||||
// It has enough fields to be called a proper event now
|
||||
let knock_event = knock_event_stub;
|
||||
// Just verify that this event isn't hilariously malformed before we sent it
|
||||
// off.
|
||||
info!("Parsing knock event");
|
||||
PduEvent::from_id_val(&event_id, stub.clone())
|
||||
.map_err(|e| err!(BadServerResponse("Invalid knock event PDU: {e:?}")))?;
|
||||
|
||||
info!("Asking {remote_server} for send_knock in room {room_id}");
|
||||
let request = federation::membership::create_knock_event::v1::Request::new(
|
||||
@@ -543,7 +307,7 @@ async fn knock_room_helper_remote(
|
||||
event_id.clone(),
|
||||
services
|
||||
.sending
|
||||
.convert_to_outgoing_federation_event(knock_event.clone())
|
||||
.convert_to_outgoing_federation_event(stub.clone())
|
||||
.await,
|
||||
);
|
||||
|
||||
@@ -554,147 +318,173 @@ async fn knock_room_helper_remote(
|
||||
|
||||
info!("send_knock finished");
|
||||
|
||||
info!("Validating send_knock response");
|
||||
services
|
||||
.rooms
|
||||
.short
|
||||
.get_or_create_shortroomid(room_id)
|
||||
.await;
|
||||
let (create_event_id, mut state) = validate_knock_state(
|
||||
services,
|
||||
&send_knock_response.knock_room_state,
|
||||
&room_version_rules,
|
||||
room_id.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
state.insert(StateEventType::RoomMember.with_state_key(sender_user.as_str()), stub);
|
||||
let create_event_json = state
|
||||
.get(&StateEventType::RoomCreate.with_state_key(""))
|
||||
.expect("must have create event in knock state by this point");
|
||||
|
||||
info!("Parsing knock event");
|
||||
let parsed_knock_pdu = PduEvent::from_id_val(&event_id, knock_event.clone())
|
||||
.map_err(|e| err!(BadServerResponse("Invalid knock event PDU: {e:?}")))?;
|
||||
|
||||
info!("Going through send_knock response knock state events");
|
||||
let state = send_knock_response
|
||||
.knock_room_state
|
||||
.iter()
|
||||
.map(|event| {
|
||||
#[allow(deprecated)]
|
||||
let raw_value = match event {
|
||||
| federation::membership::RawStrippedState::Stripped(raw_state) =>
|
||||
&raw_state.clone().into_json(),
|
||||
| federation::membership::RawStrippedState::Pdu(raw_value) => raw_value,
|
||||
| _ => panic!("unknown raw stripped state type"),
|
||||
};
|
||||
|
||||
serde_json::from_str::<CanonicalJsonObject>(raw_value.get())
|
||||
})
|
||||
.filter_map(Result::ok);
|
||||
|
||||
let mut state_map: HashMap<u64, OwnedEventId> = HashMap::new();
|
||||
|
||||
for mut event in state {
|
||||
let Some(state_key) = event.get("state_key") else {
|
||||
debug_warn!("send_knock stripped state event missing state_key: {event:?}");
|
||||
continue;
|
||||
};
|
||||
let Some(event_type) = event.get("type") else {
|
||||
debug_warn!("send_knock stripped state event missing event type: {event:?}");
|
||||
continue;
|
||||
};
|
||||
|
||||
let Ok(state_key) = serde_json::from_value::<String>(state_key.clone().into()) else {
|
||||
debug_warn!("send_knock stripped state event has invalid state_key: {event:?}");
|
||||
continue;
|
||||
};
|
||||
let Ok(event_type) = serde_json::from_value::<StateEventType>(event_type.clone().into())
|
||||
else {
|
||||
debug_warn!("send_knock stripped state event has invalid event type: {event:?}");
|
||||
continue;
|
||||
};
|
||||
|
||||
let event_id = gen_event_id(&event, &room_version_rules)?;
|
||||
let shortstatekey = services
|
||||
.rooms
|
||||
.short
|
||||
.get_or_create_shortstatekey(&event_type, &state_key)
|
||||
.await;
|
||||
|
||||
event.insert("event_id".into(), CanonicalJsonValue::String(event_id.to_string()));
|
||||
services.rooms.outlier.add_pdu_outlier(&event_id, &event);
|
||||
state_map.insert(shortstatekey, event_id.clone());
|
||||
}
|
||||
|
||||
info!("Compressing state from send_knock");
|
||||
let compressed: CompressedState = services
|
||||
.rooms
|
||||
.state_compressor
|
||||
.compress_state_events(state_map.iter().map(|(ssk, eid)| (ssk, eid.borrow())))
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
debug!("Saving compressed state");
|
||||
let HashSetCompressStateEvent {
|
||||
shortstatehash: statehash_before_knock,
|
||||
added,
|
||||
removed,
|
||||
} = services
|
||||
.rooms
|
||||
.state_compressor
|
||||
.save_state(room_id, Arc::new(compressed))
|
||||
.await?;
|
||||
|
||||
debug!("Forcing state for new room");
|
||||
// Much like when receiving an invite over federation, if we're in this room
|
||||
// we'll receive the knock PDU over /send. Otherwise, we need to add it as
|
||||
// an outlier. Since this function isn't a fallback when local knocks fail,
|
||||
// we can do this unconditionally.
|
||||
services
|
||||
.rooms
|
||||
.state
|
||||
.force_state(room_id, statehash_before_knock, added, removed, &state_lock)
|
||||
.await?;
|
||||
|
||||
let statehash_after_knock = services
|
||||
.rooms
|
||||
.state
|
||||
.append_to_state(&parsed_knock_pdu, room_id)
|
||||
.await?;
|
||||
|
||||
info!("Updating membership locally to knock state with provided stripped state events");
|
||||
// TODO: see TODO on the other call to `update_membership`
|
||||
.outlier
|
||||
.add_pdu_outlier(&create_event_id, create_event_json);
|
||||
services.rooms.state_cache.mark_as_knocked(
|
||||
sender_user,
|
||||
room_id,
|
||||
Some(state.values().collect()),
|
||||
);
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.update_membership(room_id, sender_user, &parsed_knock_pdu, false)
|
||||
.await?;
|
||||
|
||||
info!("Appending room knock event locally");
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.progress_extremities(&parsed_knock_pdu)
|
||||
.await?;
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.append_pdu(&parsed_knock_pdu, knock_event, room_id)
|
||||
.update_joined_count(room_id)
|
||||
.await;
|
||||
|
||||
info!("Setting final room state for new room");
|
||||
// We set the room state after inserting the pdu, so that we never have a
|
||||
// moment in time where events in the current room state do not exist
|
||||
services
|
||||
.rooms
|
||||
.state
|
||||
.set_room_state(room_id, statehash_after_knock, &state_lock);
|
||||
services.sync.wake(sender_user).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Validates and builds a state map based on the returned knock state.
|
||||
///
|
||||
/// This is very similar to
|
||||
/// `conduwuit_api::server::invite::validate_invite_state`, but with fixed up
|
||||
/// error messages.
|
||||
///
|
||||
/// Returns the create event's event ID, and the partial state map.
|
||||
// TODO(nex): this function is LITERALLY the same as validate_invite state,
|
||||
// except the errors and logs say "knock" instead of "invite". There's probably
|
||||
// a more elegant way to do this without duplicating the ENTIRE function.
|
||||
async fn validate_knock_state(
|
||||
services: &Services,
|
||||
knock_state: &[RawStrippedState],
|
||||
room_version_rules: &RoomVersionRules,
|
||||
room_id: OwnedRoomId,
|
||||
) -> Result<(OwnedEventId, HashMap<(StateEventType, StateKey), CanonicalJsonObject>)> {
|
||||
trace!(?knock_state, "Raw knock state");
|
||||
let mut knock_state_map: HashMap<(StateEventType, StateKey), _> =
|
||||
HashMap::with_capacity(knock_state.len());
|
||||
let mut create_event_id: Option<OwnedEventId> = None;
|
||||
|
||||
for (idx, knock_state_event) in knock_state.iter().cloned().enumerate() {
|
||||
trace!(%idx, ?knock_state_event, "Knock state event");
|
||||
// Stripped state hasn't been sent over federation since v1.16.
|
||||
let RawStrippedState::Pdu(raw_pdu) = knock_state_event else {
|
||||
debug!(%idx, "Knock state event is not a PDU");
|
||||
return Err!(Request(InvalidParam(
|
||||
"PDU in knock state (index {idx}) violates the room event format"
|
||||
)));
|
||||
};
|
||||
let (state_event_room_id, state_event_id, state_event_json) = services
|
||||
.rooms
|
||||
.event_handler
|
||||
.parse_incoming_pdu(&raw_pdu, Some(room_version_rules))
|
||||
.await
|
||||
.map_err(|e| {
|
||||
err!(Request(InvalidParam(debug_warn!("Invalid PDU in knock state: {e}"))))
|
||||
})?;
|
||||
|
||||
if state_event_room_id != room_id {
|
||||
return Err!(Request(InvalidParam(debug_warn!(
|
||||
%state_event_room_id,
|
||||
%room_id,
|
||||
"PDU in knock state ({state_event_id}) belongs to the wrong room"
|
||||
))));
|
||||
}
|
||||
|
||||
services
|
||||
.server_keys
|
||||
.verify_event_json(&state_event_json, room_version_rules)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
err!(Request(InvalidParam("Signature verification failed on knock event: {e}")))
|
||||
})?;
|
||||
|
||||
let Some(state_key) = state_event_json.get("state_key").and_then(|k| k.as_str()) else {
|
||||
return Err!(Request(InvalidParam(debug_info!(
|
||||
"PDU in knock state ({state_event_id}) is not a state event"
|
||||
))));
|
||||
};
|
||||
let Some(event_type) = state_event_json.get("type").and_then(|k| k.as_str()) else {
|
||||
return Err!(Request(InvalidParam(debug_warn!(
|
||||
"PDU in knock state ({state_event_id}) is not an event?"
|
||||
))));
|
||||
};
|
||||
|
||||
let key = StateEventType::from(event_type).with_state_key(state_key);
|
||||
match knock_state_map.entry(key) {
|
||||
| Entry::Occupied(entry) =>
|
||||
return Err!(Request(InvalidParam(
|
||||
"Duplicate state events in knock state for state key: {:?}",
|
||||
entry.key(),
|
||||
))),
|
||||
| Entry::Vacant(entry) => {
|
||||
if entry.key().0 == StateEventType::RoomCreate {
|
||||
// Ensure this is a legal create event.
|
||||
let pdu_event =
|
||||
PduEvent::from_id_val(&state_event_id, state_event_json.clone())
|
||||
.expect("must be able to create pdu event from event json");
|
||||
debug!("Validating discovered create event in knock room state");
|
||||
crate::server::invite::validate_invite_create_event(
|
||||
&pdu_event,
|
||||
room_version_rules,
|
||||
)
|
||||
.await?;
|
||||
create_event_id = Some(state_event_id);
|
||||
}
|
||||
entry.insert(state_event_json);
|
||||
},
|
||||
}
|
||||
}
|
||||
let Some(create_event_id) = create_event_id else {
|
||||
return Err!(Request(InvalidParam(debug_warn!(
|
||||
parsed_state=?knock_state_map,
|
||||
"Knock state does not contain the m.room.create event"
|
||||
))));
|
||||
};
|
||||
knock_state_map.iter().try_for_each(|(key, event_json)| {
|
||||
service::rooms::event_handler::Service::pdu_format_check_1(
|
||||
event_json,
|
||||
room_version_rules,
|
||||
&create_event_id,
|
||||
)
|
||||
.map_err(|e| {
|
||||
err!(Request(InvalidParam(
|
||||
"PDU in knock state for {key:?} violates the room event format: {e}"
|
||||
)))
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok((create_event_id, knock_state_map))
|
||||
}
|
||||
|
||||
async fn make_knock_request(
|
||||
services: &Services,
|
||||
sender_user: &UserId,
|
||||
room_id: &RoomId,
|
||||
servers: &[OwnedServerName],
|
||||
) -> Result<(federation::membership::prepare_knock_event::v1::Response, OwnedServerName)> {
|
||||
let mut make_knock_response_and_server =
|
||||
Err!(BadServerResponse("No server available to assist in knocking."));
|
||||
|
||||
let mut make_knock_counter: usize = 0;
|
||||
|
||||
for remote_server in servers {
|
||||
) -> Result<(CanonicalJsonObject, RoomVersionId, OwnedServerName)> {
|
||||
for (idx, remote_server) in servers.iter().enumerate() {
|
||||
if services.globals.server_is_ours(remote_server) {
|
||||
continue;
|
||||
}
|
||||
|
||||
info!("Asking {remote_server} for make_knock ({make_knock_counter})");
|
||||
info!("Asking {remote_server} for make_knock ({})", idx.saturating_add(1));
|
||||
|
||||
let mut request = federation::membership::prepare_knock_event::v1::Request::new(
|
||||
room_id.to_owned(),
|
||||
@@ -708,36 +498,51 @@ async fn make_knock_request(
|
||||
.await;
|
||||
|
||||
trace!("make_knock response: {make_knock_response:?}");
|
||||
make_knock_counter = make_knock_counter.saturating_add(1);
|
||||
if let Ok(r) = &make_knock_response {
|
||||
if let Err(e) = validate_remote_member_event_stub(
|
||||
&MembershipState::Knock,
|
||||
sender_user,
|
||||
room_id,
|
||||
&to_canonical_object(&r.event)?,
|
||||
) {
|
||||
warn!("make_knock response from {remote_server} failed validation: {e}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
make_knock_response_and_server = make_knock_response.map(|r| (r, remote_server.clone()));
|
||||
|
||||
if make_knock_response_and_server.is_ok() {
|
||||
break;
|
||||
}
|
||||
|
||||
if make_knock_counter > 40 {
|
||||
warn!(
|
||||
"50 servers failed to provide valid make_knock response, assuming no server can \
|
||||
assist in knocking."
|
||||
);
|
||||
make_knock_response_and_server =
|
||||
Err!(BadServerResponse("No server available to assist in knocking."));
|
||||
|
||||
return make_knock_response_and_server;
|
||||
match make_knock_response
|
||||
.and_then(|r| {
|
||||
to_canonical_object(&r.event)
|
||||
.map(|o| (o, r.room_version))
|
||||
.map_err(Into::into)
|
||||
})
|
||||
.and_then(|(stub, room_version)| {
|
||||
validate_remote_member_event_stub(
|
||||
&MembershipState::Knock,
|
||||
sender_user,
|
||||
room_id,
|
||||
&stub,
|
||||
)
|
||||
.map(|()| (stub, room_version))
|
||||
}) {
|
||||
| Ok((evt, room_version)) =>
|
||||
return Ok((evt, room_version, remote_server.to_owned())),
|
||||
| Err(e) => match e.kind() {
|
||||
| ErrorKind::IncompatibleRoomVersion(IncompatibleRoomVersionErrorData {
|
||||
room_version,
|
||||
..
|
||||
}) => {
|
||||
warn!(
|
||||
"{remote_server} reports the room we are trying to knock on is \
|
||||
v{room_version}, which we do not support."
|
||||
);
|
||||
return Err(e);
|
||||
},
|
||||
| ErrorKind::Forbidden => {
|
||||
warn!("{remote_server} refuses to let us knock: {e}.");
|
||||
return Err(e);
|
||||
},
|
||||
| ErrorKind::NotFound => {
|
||||
info!(
|
||||
"{remote_server} does not know about {room_id}: {e}. Will continue \
|
||||
trying."
|
||||
);
|
||||
},
|
||||
| _ => {
|
||||
info!("{remote_server} failed to make_knock: {e}. Will continue trying.");
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
make_knock_response_and_server
|
||||
info!("All {} servers were unable to assist in knocking {room_id} :(", servers.len());
|
||||
Err!(BadServerResponse("No server available to assist in knocking."))
|
||||
}
|
||||
@@ -414,7 +414,7 @@ struct MFederate {
|
||||
///
|
||||
/// 1. It passes auth checks (aka is valid)
|
||||
/// 2. The room is federated (there's no point persisting unfederated rooms)
|
||||
async fn validate_invite_create_event(
|
||||
pub(crate) async fn validate_invite_create_event(
|
||||
pdu: &PduEvent,
|
||||
room_version_rules: &RoomVersionRules,
|
||||
) -> Result {
|
||||
|
||||
@@ -332,6 +332,7 @@ async fn handle_room(
|
||||
room_id: OwnedRoomId,
|
||||
pdus: impl Iterator<Item = Pdu> + Send,
|
||||
) -> std::result::Result<Vec<(OwnedEventId, Result)>, TransactionError> {
|
||||
let arrived = millis_since_unix_epoch();
|
||||
let _room_lock = services
|
||||
.rooms
|
||||
.event_handler
|
||||
@@ -392,7 +393,7 @@ async fn handle_room(
|
||||
.federation_incoming_pdu_duration
|
||||
.record(start.elapsed().as_secs_f64(), std::slice::from_ref(&outcome));
|
||||
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
|
||||
.federation_incoming_pdu_lag
|
||||
.record(Duration::from_millis(lag).as_secs_f64(), &[]);
|
||||
|
||||
+12
-7
@@ -26,14 +26,19 @@ conduwuit_mods = [
|
||||
gzip_compression = [
|
||||
"reqwest/gzip",
|
||||
]
|
||||
hardened_malloc = [
|
||||
"dep:hardened_malloc-rs"
|
||||
]
|
||||
jemalloc = [
|
||||
"dep:tikv-jemalloc-sys",
|
||||
"dep:tikv-jemalloc-ctl",
|
||||
"dep:tikv-jemallocator",
|
||||
]
|
||||
# Uses mimalloc for Rust allocations and, via `override`, exports
|
||||
# malloc/free/etc. so C/C++ dependencies (RocksDB, zstd, lz4, ...) use it too.
|
||||
# Mutually exclusive with `jemalloc` on non-MSVC targets.
|
||||
mimalloc = [
|
||||
"dep:libmimalloc-sys",
|
||||
"dep:mimalloc",
|
||||
"libmimalloc-sys/override",
|
||||
]
|
||||
jemalloc_conf = []
|
||||
jemalloc_prof = [
|
||||
"tikv-jemalloc-sys/profiling",
|
||||
@@ -118,14 +123,14 @@ lock_api.workspace = true
|
||||
hyper-util.workspace = true
|
||||
resolvematrix.workspace = true
|
||||
openidconnect.workspace = true
|
||||
libmimalloc-sys.optional = true
|
||||
libmimalloc-sys.workspace = true
|
||||
mimalloc.optional = true
|
||||
mimalloc.workspace = true
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
nix.workspace = true
|
||||
|
||||
[target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies]
|
||||
hardened_malloc-rs.workspace = true
|
||||
hardened_malloc-rs.optional = true
|
||||
|
||||
[dev-dependencies]
|
||||
maplit.workspace = true
|
||||
opentelemetry_sdk.workspace = true
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
//! Default allocator with no special features
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
|
||||
pub(crate) fn metric() -> Option<(&'static str, &'static str)> { None }
|
||||
|
||||
/// Always returns Ok
|
||||
pub fn trim<I: Into<Option<usize>>>(_: I) -> crate::Result { Ok(()) }
|
||||
|
||||
@@ -12,4 +16,4 @@ pub fn memory_stats(_opts: &str) -> Option<String> { None }
|
||||
pub fn memory_usage() -> Option<String> { None }
|
||||
|
||||
#[must_use]
|
||||
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> { None }
|
||||
pub fn memory_usage_stats() -> Option<ArrayVec<(&'static str, usize), 6>> { None }
|
||||
@@ -1,18 +0,0 @@
|
||||
//! hmalloc allocator
|
||||
|
||||
#[global_allocator]
|
||||
static HMALLOC: hardened_malloc_rs::HardenedMalloc = hardened_malloc_rs::HardenedMalloc;
|
||||
|
||||
pub fn trim<I: Into<Option<usize>>>(_: I) -> crate::Result { Ok(()) }
|
||||
|
||||
#[must_use]
|
||||
//TODO: get usage
|
||||
pub fn memory_usage() -> Option<String> { None }
|
||||
|
||||
#[must_use]
|
||||
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> { None }
|
||||
|
||||
#[must_use]
|
||||
pub fn memory_stats(_opts: &str) -> Option<String> {
|
||||
Some("Extended statistics are not available from hardened_malloc.".to_owned())
|
||||
}
|
||||
+448
-148
@@ -1,9 +1,12 @@
|
||||
//! jemalloc allocator
|
||||
|
||||
use std::{
|
||||
cell::OnceCell,
|
||||
ffi::{CStr, c_char, c_void},
|
||||
any::Any,
|
||||
ffi::{CStr, CString, c_char, c_uint, c_void},
|
||||
fmt::Debug,
|
||||
panic::{self, AssertUnwindSafe},
|
||||
ptr,
|
||||
sync::OnceLock,
|
||||
};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
@@ -12,26 +15,61 @@ use tikv_jemalloc_sys as ffi;
|
||||
use tikv_jemallocator as jemalloc;
|
||||
|
||||
use crate::{
|
||||
Result, SyncRwLock, err, is_equal_to, is_nonzero,
|
||||
Result, err, is_equal_to, is_nonzero,
|
||||
utils::{math, math::Tried},
|
||||
};
|
||||
|
||||
#[cfg(feature = "jemalloc_conf")]
|
||||
#[unsafe(no_mangle)]
|
||||
pub static malloc_conf: &[u8] = const_str::concat_bytes!(
|
||||
#[repr(transparent)]
|
||||
struct MallocConf(*const c_char);
|
||||
|
||||
// SAFETY: MallocConf points to static immutable NUL-terminated bytes.
|
||||
#[cfg(feature = "jemalloc_conf")]
|
||||
unsafe impl Sync for MallocConf {}
|
||||
|
||||
#[cfg(feature = "jemalloc_conf")]
|
||||
const MALLOC_CONF_BYTES: &[u8] = const_str::concat_bytes!(
|
||||
"lg_extent_max_active_fit:4",
|
||||
",oversize_threshold:16777216",
|
||||
",tcache_max:2097152",
|
||||
",dirty_decay_ms:16000",
|
||||
",muzzy_decay_ms:144000",
|
||||
",percpu_arena:percpu",
|
||||
",metadata_thp:always",
|
||||
",background_thread:true",
|
||||
",max_background_threads:-1",
|
||||
MALLOC_CONF_PLATFORM,
|
||||
MALLOC_CONF_PROF,
|
||||
0
|
||||
);
|
||||
|
||||
#[cfg(all(feature = "jemalloc_conf", target_os = "linux"))]
|
||||
const MALLOC_CONF_PLATFORM: &str =
|
||||
",percpu_arena:percpu,metadata_thp:always,background_thread:true";
|
||||
#[cfg(all(feature = "jemalloc_conf", not(target_os = "linux")))]
|
||||
const MALLOC_CONF_PLATFORM: &str = "";
|
||||
|
||||
// Targets match `NO_UNPREFIXED_MALLOC_TARGETS` in `tikv-jemalloc-sys` when
|
||||
// `unprefixed_malloc_on_supported_platforms` is enabled.
|
||||
#[cfg(feature = "jemalloc_conf")]
|
||||
#[used]
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[cfg_attr(
|
||||
any(
|
||||
target_vendor = "apple",
|
||||
target_env = "musl",
|
||||
target_os = "android",
|
||||
target_os = "dragonfly",
|
||||
),
|
||||
unsafe(export_name = "_rjem_malloc_conf")
|
||||
)]
|
||||
#[cfg_attr(
|
||||
not(any(
|
||||
target_vendor = "apple",
|
||||
target_env = "musl",
|
||||
target_os = "android",
|
||||
target_os = "dragonfly",
|
||||
)),
|
||||
unsafe(no_mangle)
|
||||
)]
|
||||
static malloc_conf: MallocConf = MallocConf(MALLOC_CONF_BYTES.as_ptr().cast());
|
||||
|
||||
#[cfg(all(feature = "jemalloc_conf", feature = "jemalloc_prof"))]
|
||||
const MALLOC_CONF_PROF: &str = ",prof_active:false";
|
||||
#[cfg(all(feature = "jemalloc_conf", not(feature = "jemalloc_prof")))]
|
||||
@@ -39,37 +77,56 @@ const MALLOC_CONF_PROF: &str = "";
|
||||
|
||||
#[global_allocator]
|
||||
static JEMALLOC: jemalloc::Jemalloc = jemalloc::Jemalloc;
|
||||
static CONTROL: SyncRwLock<()> = SyncRwLock::new(());
|
||||
|
||||
type Name = ArrayVec<u8, NAME_MAX>;
|
||||
type Key = ArrayVec<usize, KEY_SEGS>;
|
||||
|
||||
const NAME_MAX: usize = 128;
|
||||
const KEY_SEGS: usize = 8;
|
||||
const ARENA_LIMIT: usize = 4095;
|
||||
const ARENAS_ALL: usize = 4096;
|
||||
|
||||
#[ctor::ctor(unsafe)]
|
||||
fn _static_initialization() {
|
||||
acq_epoch().expect("pre-initialization of jemalloc failed");
|
||||
acq_epoch().expect("pre-initialization of jemalloc failed");
|
||||
let mut epoch: u64 = 0;
|
||||
let mut len = size_of::<u64>();
|
||||
// SAFETY: Pre-initialize jemalloc before main() without touching Rust TLS
|
||||
// or unwinding across the constructor boundary.
|
||||
unsafe {
|
||||
ffi::mallctl(
|
||||
c"epoch".as_ptr(),
|
||||
ptr::from_mut(&mut epoch).cast::<c_void>(),
|
||||
&raw mut len,
|
||||
ptr::null_mut(),
|
||||
0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn metric() -> Option<(&'static str, &'static str)> {
|
||||
Some((
|
||||
"continuwuity.jemalloc.memory",
|
||||
"jemalloc memory statistics, when built with jemalloc_stats",
|
||||
))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
#[cfg(feature = "jemalloc_stats")]
|
||||
pub fn memory_usage() -> Option<String> {
|
||||
use std::fmt::Write;
|
||||
|
||||
let mibs = |input: usize| {
|
||||
let kibs = input / 1024;
|
||||
let kibs = u32::try_from(kibs).unwrap_or_default();
|
||||
let kibs = f64::from(kibs);
|
||||
kibs / 1024.0
|
||||
let whole = u32::try_from(input / (1024 * 1024)).unwrap_or(u32::MAX);
|
||||
let rem_kibs = u32::try_from((input / 1024) % 1024).unwrap_or_default();
|
||||
f64::from(whole) + f64::from(rem_kibs) / 1024.0
|
||||
};
|
||||
|
||||
let [allocated, active, mapped, metadata, resident, retained] =
|
||||
memory_usage_stats()?.map(|(_, bytes)| mibs(bytes));
|
||||
Some(format!(
|
||||
"allocated: {allocated:.2} MiB\nactive: {active:.2} MiB\nmapped: {mapped:.2} \
|
||||
MiB\nmetadata: {metadata:.2} MiB\nresident: {resident:.2} MiB\nretained: {retained:.2} \
|
||||
MiB\n"
|
||||
))
|
||||
let mut out = String::new();
|
||||
for (name, bytes) in memory_usage_stats()? {
|
||||
writeln!(out, "{name}: {:.2} MiB", mibs(bytes)).ok()?;
|
||||
}
|
||||
|
||||
Some(out)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@@ -78,184 +135,259 @@ pub fn memory_usage() -> Option<String> { None }
|
||||
|
||||
#[must_use]
|
||||
#[cfg(feature = "jemalloc_stats")]
|
||||
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> {
|
||||
pub fn memory_usage_stats() -> Option<ArrayVec<(&'static str, usize), 6>> {
|
||||
use mallctl::stats;
|
||||
|
||||
// Acquire the epoch; ensure latest stats are pulled in
|
||||
acq_epoch().ok()?;
|
||||
// Advance the epoch; ensure latest stats are pulled in
|
||||
inc_epoch().ok()?;
|
||||
|
||||
Some([
|
||||
Some(ArrayVec::from([
|
||||
("allocated", stats::allocated::read().unwrap_or_default()),
|
||||
("active", stats::active::read().unwrap_or_default()),
|
||||
("mapped", stats::mapped::read().unwrap_or_default()),
|
||||
("metadata", stats::metadata::read().unwrap_or_default()),
|
||||
("resident", stats::resident::read().unwrap_or_default()),
|
||||
("retained", stats::retained::read().unwrap_or_default()),
|
||||
])
|
||||
]))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
#[cfg(not(feature = "jemalloc_stats"))]
|
||||
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> { None }
|
||||
pub fn memory_usage_stats() -> Option<ArrayVec<(&'static str, usize), 6>> { None }
|
||||
|
||||
struct StatsPrintState {
|
||||
buf: String,
|
||||
max_len: usize,
|
||||
panic: Option<Box<dyn Any + Send>>,
|
||||
}
|
||||
|
||||
pub fn memory_stats(opts: &str) -> Option<String> {
|
||||
const MAX_LENGTH: usize = 1_048_576;
|
||||
|
||||
let mut str = String::new();
|
||||
let opaque = std::ptr::from_mut(&mut str).cast::<c_void>();
|
||||
let opts_p: *const c_char = std::ffi::CString::new(opts)
|
||||
.expect("cstring")
|
||||
.into_raw()
|
||||
.cast_const();
|
||||
let opts = CString::new(opts).ok()?;
|
||||
|
||||
// Acquire the epoch; ensure latest stats are pulled in
|
||||
acq_epoch().ok()?;
|
||||
let mut state = StatsPrintState {
|
||||
buf: String::new(),
|
||||
max_len: MAX_LENGTH,
|
||||
panic: None,
|
||||
};
|
||||
let opaque = ptr::from_mut(&mut state).cast::<c_void>();
|
||||
|
||||
// SAFETY: calls malloc_stats_print() with our string instance which must
|
||||
// remain in this frame. https://docs.rs/tikv-jemalloc-sys/latest/tikv_jemalloc_sys/fn.malloc_stats_print.html
|
||||
unsafe { ffi::malloc_stats_print(Some(malloc_stats_cb), opaque, opts_p) };
|
||||
// SAFETY: `state` and `opts` remain live in this frame for the duration of
|
||||
// `malloc_stats_print()`, which invokes `malloc_stats_cb` synchronously.
|
||||
unsafe { ffi::malloc_stats_print(Some(malloc_stats_cb), opaque, opts.as_ptr()) };
|
||||
|
||||
str.truncate(MAX_LENGTH);
|
||||
if let Some(payload) = state.panic {
|
||||
panic::resume_unwind(payload);
|
||||
}
|
||||
|
||||
Some(str)
|
||||
Some(state.buf)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn malloc_stats_cb(opaque: *mut c_void, msg: *const c_char) {
|
||||
// SAFETY: we have to trust the opaque points to our String
|
||||
let res: &mut String = unsafe {
|
||||
opaque
|
||||
.cast::<String>()
|
||||
.as_mut()
|
||||
.expect("failed to cast void* to &mut String")
|
||||
// SAFETY: `opaque` points to `StatsPrintState` on the caller's stack.
|
||||
let Some(state) = (unsafe { opaque.cast::<StatsPrintState>().as_mut() }) else {
|
||||
return;
|
||||
};
|
||||
|
||||
// SAFETY: we have to trust the string is null terminated.
|
||||
if state.panic.is_some() || msg.is_null() || state.buf.len() >= state.max_len {
|
||||
return;
|
||||
}
|
||||
|
||||
// SAFETY: jemalloc guarantees `msg` is a valid NUL-terminated C string.
|
||||
let msg = unsafe { CStr::from_ptr(msg) };
|
||||
|
||||
let msg = String::from_utf8_lossy(msg.to_bytes());
|
||||
res.push_str(msg.as_ref());
|
||||
if let Err(err) = panic::catch_unwind(AssertUnwindSafe(|| {
|
||||
let msg = String::from_utf8_lossy(msg.to_bytes());
|
||||
let remaining = state.max_len.saturating_sub(state.buf.len());
|
||||
if msg.len() <= remaining {
|
||||
state.buf.push_str(msg.as_ref());
|
||||
} else {
|
||||
if let Some(prefix) = msg.get(..msg.floor_char_boundary(remaining)) {
|
||||
state.buf.push_str(prefix);
|
||||
}
|
||||
state.max_len = state.buf.len();
|
||||
}
|
||||
})) {
|
||||
state.panic = Some(err);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! mallctl {
|
||||
($name:expr_2021) => {{
|
||||
thread_local! {
|
||||
static KEY: OnceCell<Key> = OnceCell::default();
|
||||
};
|
||||
($name:literal) => {{
|
||||
static KEY: OnceLock<Key> = OnceLock::new();
|
||||
|
||||
KEY.with(|once| {
|
||||
once.get_or_init(move || key($name).expect("failed to translate name into mib key"))
|
||||
.clone()
|
||||
})
|
||||
KEY.get_or_init(|| key($name).expect("failed to translate name into mib key"))
|
||||
}};
|
||||
}
|
||||
|
||||
pub mod this_thread {
|
||||
use super::{Debug, Key, OnceCell, Result, is_nonzero, key, math};
|
||||
|
||||
thread_local! {
|
||||
static ALLOCATED_BYTES: OnceCell<&'static u64> = const { OnceCell::new() };
|
||||
static DEALLOCATED_BYTES: OnceCell<&'static u64> = const { OnceCell::new() };
|
||||
}
|
||||
use super::{Debug, Key, OnceLock, Result, c_uint, is_nonzero, key, math};
|
||||
|
||||
pub fn trim() -> Result { decay().and_then(|()| purge()) }
|
||||
|
||||
pub fn purge() -> Result { notify(mallctl!("arena.0.purge")) }
|
||||
pub fn purge() -> Result {
|
||||
// SAFETY: `arena.<i>.purge` is an `arena.<i>.*` notification ctl.
|
||||
unsafe { notify(mallctl!("arena.0.purge")) }
|
||||
}
|
||||
|
||||
pub fn decay() -> Result { notify(mallctl!("arena.0.decay")) }
|
||||
pub fn decay() -> Result {
|
||||
// SAFETY: `arena.<i>.decay` is an `arena.<i>.*` notification ctl.
|
||||
unsafe { notify(mallctl!("arena.0.decay")) }
|
||||
}
|
||||
|
||||
pub fn idle() -> Result { super::notify(&mallctl!("thread.idle")) }
|
||||
pub fn idle() -> Result {
|
||||
// SAFETY: `thread.idle` is a non-indexed notification ctl.
|
||||
unsafe { super::notify(mallctl!("thread.idle")) }
|
||||
}
|
||||
|
||||
pub fn flush() -> Result { super::notify(&mallctl!("thread.tcache.flush")) }
|
||||
pub fn flush() -> Result {
|
||||
// SAFETY: `thread.tcache.flush` is a non-indexed notification ctl.
|
||||
unsafe { super::notify(mallctl!("thread.tcache.flush")) }
|
||||
}
|
||||
|
||||
pub fn set_muzzy_decay(decay_ms: isize) -> Result<isize> {
|
||||
set(mallctl!("arena.0.muzzy_decay_ms"), decay_ms)
|
||||
// SAFETY: `arena.<i>.muzzy_decay_ms` has C type `ssize_t`.
|
||||
unsafe { set(mallctl!("arena.0.muzzy_decay_ms"), decay_ms) }
|
||||
}
|
||||
|
||||
pub fn get_muzzy_decay() -> Result<isize> { get(mallctl!("arena.0.muzzy_decay_ms")) }
|
||||
pub fn get_muzzy_decay() -> Result<isize> {
|
||||
// SAFETY: `arena.<i>.muzzy_decay_ms` has C type `ssize_t`.
|
||||
unsafe { get(mallctl!("arena.0.muzzy_decay_ms")) }
|
||||
}
|
||||
|
||||
pub fn set_dirty_decay(decay_ms: isize) -> Result<isize> {
|
||||
set(mallctl!("arena.0.dirty_decay_ms"), decay_ms)
|
||||
// SAFETY: `arena.<i>.dirty_decay_ms` has C type `ssize_t`.
|
||||
unsafe { set(mallctl!("arena.0.dirty_decay_ms"), decay_ms) }
|
||||
}
|
||||
|
||||
pub fn get_dirty_decay() -> Result<isize> { get(mallctl!("arena.0.dirty_decay_ms")) }
|
||||
pub fn get_dirty_decay() -> Result<isize> {
|
||||
// SAFETY: `arena.<i>.dirty_decay_ms` has C type `ssize_t`.
|
||||
unsafe { get(mallctl!("arena.0.dirty_decay_ms")) }
|
||||
}
|
||||
|
||||
pub fn cache_enable(enable: bool) -> Result<bool> {
|
||||
super::set::<u8>(&mallctl!("thread.tcache.enabled"), enable.into()).map(is_nonzero!())
|
||||
// SAFETY: `thread.tcache.enabled` has C type `bool` (1 byte on
|
||||
// non-MSVC).
|
||||
unsafe { super::set::<u8>(mallctl!("thread.tcache.enabled"), enable.into()) }
|
||||
.map(is_nonzero!())
|
||||
}
|
||||
|
||||
pub fn is_cache_enabled() -> Result<bool> {
|
||||
super::get::<u8>(&mallctl!("thread.tcache.enabled")).map(is_nonzero!())
|
||||
// SAFETY: `thread.tcache.enabled` has C type `bool` (1 byte on
|
||||
// non-MSVC).
|
||||
unsafe { super::get::<u8>(mallctl!("thread.tcache.enabled")) }.map(is_nonzero!())
|
||||
}
|
||||
|
||||
pub fn set_arena(id: usize) -> Result<usize> {
|
||||
super::set::<u32>(&mallctl!("thread.arena"), id.try_into()?).and_then(math::try_into)
|
||||
// SAFETY: `thread.arena` has C type `unsigned`.
|
||||
unsafe { super::set::<c_uint>(mallctl!("thread.arena"), id.try_into()?) }
|
||||
.and_then(math::try_into)
|
||||
}
|
||||
|
||||
pub fn arena_id() -> Result<usize> {
|
||||
super::get::<u32>(&mallctl!("thread.arena")).and_then(math::try_into)
|
||||
// SAFETY: `thread.arena` has C type `unsigned`.
|
||||
unsafe { super::get::<c_uint>(mallctl!("thread.arena")) }.and_then(math::try_into)
|
||||
}
|
||||
|
||||
pub fn prof_enable(enable: bool) -> Result<bool> {
|
||||
super::set::<u8>(&mallctl!("thread.prof.active"), enable.into()).map(is_nonzero!())
|
||||
// SAFETY: `thread.prof.active` has C type `bool` (1 byte on non-MSVC).
|
||||
unsafe { super::set::<u8>(mallctl!("thread.prof.active"), enable.into()) }
|
||||
.map(is_nonzero!())
|
||||
}
|
||||
|
||||
pub fn is_prof_enabled() -> Result<bool> {
|
||||
super::get::<u8>(&mallctl!("thread.prof.active")).map(is_nonzero!())
|
||||
// SAFETY: `thread.prof.active` has C type `bool` (1 byte on non-MSVC).
|
||||
unsafe { super::get::<u8>(mallctl!("thread.prof.active")) }.map(is_nonzero!())
|
||||
}
|
||||
|
||||
pub fn reset_peak() -> Result { super::notify(&mallctl!("thread.peak.reset")) }
|
||||
pub fn reset_peak() -> Result {
|
||||
// SAFETY: `thread.peak.reset` is a non-indexed notification ctl.
|
||||
unsafe { super::notify(mallctl!("thread.peak.reset")) }
|
||||
}
|
||||
|
||||
pub fn peak() -> Result<u64> { super::get(&mallctl!("thread.peak.read")) }
|
||||
pub fn peak() -> Result<u64> {
|
||||
// SAFETY: `thread.peak.read` has C type `uint64_t`.
|
||||
unsafe { super::get(mallctl!("thread.peak.read")) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn allocated() -> u64 {
|
||||
*ALLOCATED_BYTES.with(|once| init_tls_cell(once, "thread.allocatedp"))
|
||||
// SAFETY: `thread.allocated` has C type `uint64_t`.
|
||||
unsafe { super::get(mallctl!("thread.allocated")) }.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn deallocated() -> u64 {
|
||||
*DEALLOCATED_BYTES.with(|once| init_tls_cell(once, "thread.deallocatedp"))
|
||||
// SAFETY: `thread.deallocated` has C type `uint64_t`.
|
||||
unsafe { super::get(mallctl!("thread.deallocated")) }.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn notify(key: Key) -> Result { super::notify_by_arena(Some(arena_id()?), key) }
|
||||
/// # Safety
|
||||
/// Caller must ensure `key` is an `arena.<i>.*` notification MIB
|
||||
/// (`key.len() >= 2`).
|
||||
unsafe fn notify(key: &Key) -> Result {
|
||||
let mut key = key.clone();
|
||||
// `arena_id()` returns this thread's own valid arena (< narenas <
|
||||
// ARENA_LIMIT), so we skip `validate_arena_id()` to avoid locking
|
||||
// `ctl_mtx` on hot paths like `decay()`.
|
||||
key[1] = arena_id()?;
|
||||
// SAFETY: Caller guarantees `key` is an `arena.<i>.*` notification MIB
|
||||
// and `arena_id()` returns a valid arena index.
|
||||
unsafe { super::notify(&key) }
|
||||
}
|
||||
|
||||
fn set<T>(key: Key, val: T) -> Result<T>
|
||||
/// # Safety
|
||||
/// Caller must ensure `key` is an `arena.<i>.*` MIB and `T` matches its
|
||||
/// exact C type.
|
||||
unsafe fn set<T>(key: &Key, val: T) -> Result<T>
|
||||
where
|
||||
T: Copy + Debug,
|
||||
{
|
||||
super::set_by_arena(Some(arena_id()?), key, val)
|
||||
let mut key = key.clone();
|
||||
// `arena_id()` is already a valid arena index; skip
|
||||
// `validate_arena_id()`.
|
||||
key[1] = arena_id()?;
|
||||
// SAFETY: Caller guarantees `T` matches `key`.
|
||||
unsafe { super::set(&key, val) }
|
||||
}
|
||||
|
||||
fn get<T>(key: Key) -> Result<T>
|
||||
/// # Safety
|
||||
/// Caller must ensure `key` is an `arena.<i>.*` MIB and `T` matches its
|
||||
/// exact C type.
|
||||
unsafe fn get<T>(key: &Key) -> Result<T>
|
||||
where
|
||||
T: Copy + Debug,
|
||||
{
|
||||
super::get_by_arena(Some(arena_id()?), key)
|
||||
}
|
||||
|
||||
fn init_tls_cell(cell: &OnceCell<&'static u64>, name: &str) -> &'static u64 {
|
||||
cell.get_or_init(|| {
|
||||
let ptr: *const u64 = super::get(&mallctl!(name)).expect("failed to obtain pointer");
|
||||
|
||||
// SAFETY: ptr points directly to the internal state of jemalloc for
|
||||
// this thread
|
||||
unsafe { ptr.as_ref() }.expect("pointer must not be null")
|
||||
})
|
||||
let mut key = key.clone();
|
||||
// `arena_id()` is already a valid arena index; skip
|
||||
// `validate_arena_id()`.
|
||||
key[1] = arena_id()?;
|
||||
// SAFETY: Caller guarantees `T` matches `key`.
|
||||
unsafe { super::get(&key) }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stats_reset() -> Result { notify(&mallctl!("stats.mutexes.reset")) }
|
||||
pub fn stats_reset() -> Result {
|
||||
// SAFETY: `stats.mutexes.reset` is a non-indexed notification ctl.
|
||||
unsafe { notify(mallctl!("stats.mutexes.reset")) }
|
||||
}
|
||||
|
||||
pub fn prof_reset() -> Result { notify(&mallctl!("prof.reset")) }
|
||||
pub fn prof_reset() -> Result {
|
||||
// SAFETY: `prof.reset` is a non-indexed notification ctl.
|
||||
unsafe { notify(mallctl!("prof.reset")) }
|
||||
}
|
||||
|
||||
pub fn prof_enable(enable: bool) -> Result<bool> {
|
||||
set::<u8>(&mallctl!("prof.active"), enable.into()).map(is_nonzero!())
|
||||
// SAFETY: `prof.active` has C type `bool` (1 byte on non-MSVC).
|
||||
unsafe { set::<u8>(mallctl!("prof.active"), enable.into()) }.map(is_nonzero!())
|
||||
}
|
||||
|
||||
pub fn is_prof_enabled() -> Result<bool> {
|
||||
get::<u8>(&mallctl!("prof.active")).map(is_nonzero!())
|
||||
// SAFETY: `prof.active` has C type `bool` (1 byte on non-MSVC).
|
||||
unsafe { get::<u8>(mallctl!("prof.active")) }.map(is_nonzero!())
|
||||
}
|
||||
|
||||
pub fn trim<I: Into<Option<usize>> + Copy>(arena: I) -> Result {
|
||||
@@ -263,31 +395,40 @@ pub fn trim<I: Into<Option<usize>> + Copy>(arena: I) -> Result {
|
||||
}
|
||||
|
||||
pub fn purge<I: Into<Option<usize>>>(arena: I) -> Result {
|
||||
notify_by_arena(arena.into(), mallctl!("arena.4096.purge"))
|
||||
// SAFETY: `arena.<i>.purge` is an `arena.<i>.*` notification ctl.
|
||||
unsafe { notify_by_arena(arena.into(), mallctl!("arena.4096.purge")) }
|
||||
}
|
||||
|
||||
pub fn decay<I: Into<Option<usize>>>(arena: I) -> Result {
|
||||
notify_by_arena(arena.into(), mallctl!("arena.4096.decay"))
|
||||
// SAFETY: `arena.<i>.decay` is an `arena.<i>.*` notification ctl.
|
||||
unsafe { notify_by_arena(arena.into(), mallctl!("arena.4096.decay")) }
|
||||
}
|
||||
|
||||
pub fn set_muzzy_decay<I: Into<Option<usize>>>(arena: I, decay_ms: isize) -> Result<isize> {
|
||||
match arena.into() {
|
||||
| Some(arena) =>
|
||||
set_by_arena(Some(arena), mallctl!("arena.4096.muzzy_decay_ms"), decay_ms),
|
||||
| _ => set(&mallctl!("arenas.muzzy_decay_ms"), decay_ms),
|
||||
// SAFETY: `arena.<i>.muzzy_decay_ms` has C type `ssize_t`.
|
||||
| Some(arena) => unsafe {
|
||||
set_by_arena(arena, mallctl!("arena.0.muzzy_decay_ms"), decay_ms)
|
||||
},
|
||||
// SAFETY: `arenas.muzzy_decay_ms` has C type `ssize_t`.
|
||||
| _ => unsafe { set(mallctl!("arenas.muzzy_decay_ms"), decay_ms) },
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_dirty_decay<I: Into<Option<usize>>>(arena: I, decay_ms: isize) -> Result<isize> {
|
||||
match arena.into() {
|
||||
| Some(arena) =>
|
||||
set_by_arena(Some(arena), mallctl!("arena.4096.dirty_decay_ms"), decay_ms),
|
||||
| _ => set(&mallctl!("arenas.dirty_decay_ms"), decay_ms),
|
||||
// SAFETY: `arena.<i>.dirty_decay_ms` has C type `ssize_t`.
|
||||
| Some(arena) => unsafe {
|
||||
set_by_arena(arena, mallctl!("arena.0.dirty_decay_ms"), decay_ms)
|
||||
},
|
||||
// SAFETY: `arenas.dirty_decay_ms` has C type `ssize_t`.
|
||||
| _ => unsafe { set(mallctl!("arenas.dirty_decay_ms"), decay_ms) },
|
||||
}
|
||||
}
|
||||
|
||||
pub fn background_thread_enable(enable: bool) -> Result<bool> {
|
||||
set::<u8>(&mallctl!("background_thread"), enable.into()).map(is_nonzero!())
|
||||
// SAFETY: `background_thread` has C type `bool` (1 byte on non-MSVC).
|
||||
unsafe { set::<u8>(mallctl!("background_thread"), enable.into()) }.map(is_nonzero!())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -303,83 +444,138 @@ pub fn is_percpu_arena() -> bool { percpu_arenas().is_ok_and(is_equal_to!("percp
|
||||
pub fn is_phycpu_arena() -> bool { percpu_arenas().is_ok_and(is_equal_to!("phycpu")) }
|
||||
|
||||
pub fn percpu_arenas() -> Result<&'static str> {
|
||||
let ptr = get::<*const c_char>(&mallctl!("opt.percpu_arena"))?;
|
||||
//SAFETY: ptr points to a null-terminated string returned for
|
||||
// opt.percpu_arena.
|
||||
// SAFETY: `opt.percpu_arena` has C type `const char *`.
|
||||
let ptr = unsafe { get::<*const c_char>(mallctl!("opt.percpu_arena")) }?;
|
||||
if ptr.is_null() {
|
||||
return Err(err!("mallctl: opt.percpu_arena returned NULL"));
|
||||
}
|
||||
|
||||
// SAFETY: `ptr` is non-null and points to a static NUL-terminated string
|
||||
// returned by jemalloc for `opt.percpu_arena`.
|
||||
let cstr = unsafe { CStr::from_ptr(ptr) };
|
||||
cstr.to_str().map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn arenas() -> Result<usize> {
|
||||
get::<u32>(&mallctl!("arenas.narenas")).and_then(math::try_into)
|
||||
// SAFETY: `arenas.narenas` has C type `unsigned`.
|
||||
unsafe { get::<c_uint>(mallctl!("arenas.narenas")) }.and_then(math::try_into)
|
||||
}
|
||||
|
||||
pub fn inc_epoch() -> Result<u64> { xchg(&mallctl!("epoch"), 1_u64) }
|
||||
|
||||
pub fn acq_epoch() -> Result<u64> { xchg(&mallctl!("epoch"), 0_u64) }
|
||||
|
||||
fn notify_by_arena(id: Option<usize>, mut key: Key) -> Result {
|
||||
key[1] = id.unwrap_or(4096);
|
||||
notify(&key)
|
||||
pub fn inc_epoch() -> Result<u64> {
|
||||
// SAFETY: `epoch` has C type `uint64_t`.
|
||||
unsafe { xchg(mallctl!("epoch"), 1_u64) }
|
||||
}
|
||||
|
||||
fn set_by_arena<T>(id: Option<usize>, mut key: Key, val: T) -> Result<T>
|
||||
pub fn acq_epoch() -> Result<u64> {
|
||||
// SAFETY: `epoch` has C type `uint64_t`.
|
||||
unsafe { get(mallctl!("epoch")) }
|
||||
}
|
||||
|
||||
fn validate_arena_id(id: usize, allow_all: bool) -> Result<usize> {
|
||||
if allow_all && id == ARENAS_ALL {
|
||||
return Ok(id);
|
||||
}
|
||||
|
||||
let narenas = arenas()?.min(ARENA_LIMIT);
|
||||
if id < narenas {
|
||||
Ok(id)
|
||||
} else {
|
||||
Err(err!("mallctl: invalid arena index {id} (narenas: {narenas})"))
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// Caller must ensure `key` is an `arena.<i>.*` notification MIB
|
||||
/// (`key.len() >= 2`).
|
||||
unsafe fn notify_by_arena(id: Option<usize>, key: &Key) -> Result {
|
||||
let mut key = key.clone();
|
||||
key[1] = match id {
|
||||
| Some(id) => validate_arena_id(id, true)?,
|
||||
| None => ARENAS_ALL,
|
||||
};
|
||||
// SAFETY: Caller guarantees `key` is an `arena.<i>.*` notification MIB and
|
||||
// `key[1]` has been validated above.
|
||||
unsafe { notify(&key) }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// Caller must ensure `key` is an `arena.<i>.*` MIB (`key.len() >= 2`) and `T`
|
||||
/// matches its exact C type.
|
||||
unsafe fn set_by_arena<T>(id: usize, key: &Key, val: T) -> Result<T>
|
||||
where
|
||||
T: Copy + Debug,
|
||||
{
|
||||
key[1] = id.unwrap_or(4096);
|
||||
set(&key, val)
|
||||
let mut key = key.clone();
|
||||
key[1] = validate_arena_id(id, false)?;
|
||||
// SAFETY: Caller guarantees `T` matches `key`.
|
||||
unsafe { set(&key, val) }
|
||||
}
|
||||
|
||||
fn get_by_arena<T>(id: Option<usize>, mut key: Key) -> Result<T>
|
||||
/// # Safety
|
||||
/// Caller must ensure `key` is a valid notification MIB and any indexed arena
|
||||
/// component is within bounds.
|
||||
unsafe fn notify(key: &Key) -> Result {
|
||||
// SAFETY: jemalloc notification ctls require `oldp`, `oldlenp`, and `newp`
|
||||
// to be NULL and `newlen` to be 0 (otherwise `EPERM` is returned).
|
||||
let ret = unsafe {
|
||||
ffi::mallctlbymib(
|
||||
key.as_ptr(),
|
||||
key.len(),
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
0,
|
||||
)
|
||||
};
|
||||
if ret == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(err!("mallctl: {}", std::io::Error::from_raw_os_error(ret)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Does not advance `epoch`; callers reading cached `stats.*` must call
|
||||
/// `inc_epoch()` explicitly.
|
||||
///
|
||||
/// # Safety
|
||||
/// Caller must ensure `T` matches the exact C type expected by `key`.
|
||||
unsafe fn set<T>(key: &Key, val: T) -> Result<T>
|
||||
where
|
||||
T: Copy + Debug,
|
||||
{
|
||||
key[1] = id.unwrap_or(4096);
|
||||
get(&key)
|
||||
}
|
||||
|
||||
fn notify(key: &Key) -> Result { xchg(key, ()) }
|
||||
|
||||
fn set<T>(key: &Key, val: T) -> Result<T>
|
||||
where
|
||||
T: Copy + Debug,
|
||||
{
|
||||
let _lock = CONTROL.write();
|
||||
let res = xchg(key, val)?;
|
||||
inc_epoch()?;
|
||||
|
||||
Ok(res)
|
||||
// SAFETY: Caller guarantees `T` matches `key`.
|
||||
unsafe { xchg(key, val) }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// Caller must ensure `T` matches the exact C type expected by `key`.
|
||||
#[tracing::instrument(
|
||||
name = "get",
|
||||
level = "trace",
|
||||
skip_all,
|
||||
fields(?key)
|
||||
)]
|
||||
fn get<T>(key: &Key) -> Result<T>
|
||||
unsafe fn get<T>(key: &Key) -> Result<T>
|
||||
where
|
||||
T: Copy + Debug,
|
||||
{
|
||||
acq_epoch()?;
|
||||
acq_epoch()?;
|
||||
|
||||
// SAFETY: T must be perfectly valid to receive value.
|
||||
// SAFETY: Caller guarantees `T` matches the C type returned for `key`.
|
||||
unsafe { mallctl::raw::read_mib(key.as_slice()) }.map_err(map_err)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// Caller must ensure `T` matches the exact C type expected by `key`.
|
||||
#[tracing::instrument(
|
||||
name = "xchg",
|
||||
level = "trace",
|
||||
skip_all,
|
||||
fields(?key, ?val)
|
||||
)]
|
||||
fn xchg<T>(key: &Key, val: T) -> Result<T>
|
||||
unsafe fn xchg<T>(key: &Key, val: T) -> Result<T>
|
||||
where
|
||||
T: Copy + Debug,
|
||||
{
|
||||
// SAFETY: T must be the exact expected type.
|
||||
// SAFETY: Caller guarantees `T` matches the C type expected by `key`.
|
||||
unsafe { mallctl::raw::update_mib(key.as_slice(), val) }.map_err(map_err)
|
||||
}
|
||||
|
||||
@@ -387,6 +583,9 @@ fn key(name: &str) -> Result<Key> {
|
||||
// tikv asserts the output buffer length is tight to the number of required
|
||||
// mibs so we slice that down here.
|
||||
let segs = name.chars().filter(is_equal_to!(&'.')).count().try_add(1)?;
|
||||
if segs > KEY_SEGS {
|
||||
return Err(err!("mallctl: key has too many segments ({segs} > {KEY_SEGS})"));
|
||||
}
|
||||
|
||||
let name = self::name(name)?;
|
||||
let mut buf = [0_usize; KEY_SEGS];
|
||||
@@ -396,6 +595,10 @@ fn key(name: &str) -> Result<Key> {
|
||||
}
|
||||
|
||||
fn name(name: &str) -> Result<Name> {
|
||||
if name.as_bytes().contains(&0) {
|
||||
return Err(err!("mallctl: key contains interior NUL byte"));
|
||||
}
|
||||
|
||||
let mut buf = Name::new();
|
||||
buf.try_extend_from_slice(name.as_bytes())?;
|
||||
buf.try_extend_from_slice(b"\0")?;
|
||||
@@ -406,3 +609,100 @@ fn name(name: &str) -> Result<Name> {
|
||||
fn map_err(error: tikv_jemalloc_ctl::Error) -> crate::Error {
|
||||
err!("mallctl: {}", error.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn notify_ctls_succeed() {
|
||||
this_thread::flush().expect("thread.tcache.flush");
|
||||
this_thread::decay().expect("arena.<i>.decay");
|
||||
this_thread::purge().expect("arena.<i>.purge");
|
||||
this_thread::trim().expect("this_thread::trim");
|
||||
trim(None).expect("trim(None)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "jemalloc_stats")]
|
||||
fn allocated_and_deallocated_do_not_alias() {
|
||||
let a0 = this_thread::allocated();
|
||||
let d0 = this_thread::deallocated();
|
||||
|
||||
let buf = std::hint::black_box(vec![0_u8; 64 * 1024]);
|
||||
let a1 = this_thread::allocated();
|
||||
assert!(a1 > a0, "expected allocated to increase: {a0} -> {a1}");
|
||||
|
||||
drop(buf);
|
||||
let d1 = this_thread::deallocated();
|
||||
assert!(d1 > d0, "expected deallocated to increase: {d0} -> {d1}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memory_stats_handles_valid_and_nul_opts() {
|
||||
assert!(memory_stats("invalid\0opts").is_none());
|
||||
let stats = memory_stats("gmal").expect("memory_stats");
|
||||
assert!(!stats.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_too_many_segments_returns_err() { key("a.b.c.d.e.f.g.h.i").unwrap_err(); }
|
||||
|
||||
#[test]
|
||||
fn key_interior_nul_returns_err() { key("a.b\0.c").unwrap_err(); }
|
||||
|
||||
#[test]
|
||||
fn arena_index_bounds_rejected() {
|
||||
purge(Some(ARENAS_ALL)).expect("purge(MALLCTL_ARENAS_ALL)");
|
||||
decay(Some(ARENAS_ALL)).expect("decay(MALLCTL_ARENAS_ALL)");
|
||||
|
||||
let narenas = arenas().expect("arenas.narenas");
|
||||
purge(Some(narenas)).unwrap_err();
|
||||
decay(Some(narenas)).unwrap_err();
|
||||
set_dirty_decay(Some(narenas), -1).unwrap_err();
|
||||
set_muzzy_decay(Some(narenas), -1).unwrap_err();
|
||||
|
||||
purge(Some(4097)).unwrap_err();
|
||||
decay(Some(4097)).unwrap_err();
|
||||
trim(Some(4097)).unwrap_err();
|
||||
purge(Some(usize::MAX)).unwrap_err();
|
||||
|
||||
set_dirty_decay(Some(ARENAS_ALL), -1).unwrap_err();
|
||||
set_muzzy_decay(Some(ARENAS_ALL), -1).unwrap_err();
|
||||
set_dirty_decay(Some(4097), -1).unwrap_err();
|
||||
set_muzzy_decay(Some(4097), -1).unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "jemalloc_conf")]
|
||||
fn malloc_conf_is_applied() {
|
||||
if std::env::var_os("MALLOC_CONF").is_some()
|
||||
|| std::env::var_os("_RJEM_MALLOC_CONF").is_some()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// SAFETY: `opt.dirty_decay_ms` and `opt.muzzy_decay_ms` have C type
|
||||
// `ssize_t`.
|
||||
let dirty =
|
||||
unsafe { get::<isize>(mallctl!("opt.dirty_decay_ms")) }.expect("opt.dirty_decay_ms");
|
||||
// SAFETY: Same as above
|
||||
let muzzy =
|
||||
unsafe { get::<isize>(mallctl!("opt.muzzy_decay_ms")) }.expect("opt.muzzy_decay_ms");
|
||||
assert_eq!(dirty, 16_000, "expected malloc_conf dirty_decay_ms:16000");
|
||||
assert_eq!(muzzy, 144_000, "expected malloc_conf muzzy_decay_ms:144000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn percpu_arenas_returns_valid_mode() {
|
||||
let mode = percpu_arenas().expect("opt.percpu_arena");
|
||||
assert!(matches!(mode, "disabled" | "percpu" | "phycpu"), "unexpected mode: {mode}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn epoch_read_and_advance() {
|
||||
let e0 = acq_epoch().expect("acq_epoch");
|
||||
let e1 = inc_epoch().expect("inc_epoch");
|
||||
assert!(e1 > e0, "expected inc_epoch to advance epoch: {e0} -> {e1}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
//! mimalloc allocator
|
||||
|
||||
use std::{
|
||||
any::Any,
|
||||
ffi::{CStr, c_void},
|
||||
panic::{self, AssertUnwindSafe},
|
||||
ptr,
|
||||
};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use libmimalloc_sys as ffi;
|
||||
use mimalloc::MiMalloc;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[global_allocator]
|
||||
static MIMALLOC: MiMalloc = MiMalloc;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct StatCount {
|
||||
current: i64,
|
||||
peak: i64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Stats {
|
||||
reserved: StatCount,
|
||||
committed: StatCount,
|
||||
purged: i64,
|
||||
reset: i64,
|
||||
}
|
||||
|
||||
trait OutputFnChar {
|
||||
type Char;
|
||||
}
|
||||
|
||||
impl<C> OutputFnChar for Option<unsafe extern "C" fn(*const C, *mut c_void)> {
|
||||
type Char = C;
|
||||
}
|
||||
|
||||
type MiChar = <ffi::mi_output_fun as OutputFnChar>::Char;
|
||||
|
||||
struct StatsPrintState {
|
||||
buf: String,
|
||||
max_len: usize,
|
||||
panic: Option<Box<dyn Any + Send>>,
|
||||
}
|
||||
|
||||
pub(crate) fn metric() -> Option<(&'static str, &'static str)> {
|
||||
Some(("continuwuity.mimalloc.memory", "mimalloc memory statistics"))
|
||||
}
|
||||
|
||||
pub fn trim<I: Into<Option<usize>>>(_: I) -> crate::Result {
|
||||
// SAFETY: `mi_collect` is thread-safe and takes a single boolean flag.
|
||||
unsafe { ffi::mi_collect(true) };
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn read_stats() -> Option<Stats> {
|
||||
let stats = MiMalloc::stats_json().ok()?;
|
||||
let json = stats.to_str().ok()?;
|
||||
serde_json::from_str(json).ok()
|
||||
}
|
||||
|
||||
fn non_neg_usize(value: i64) -> usize { usize::try_from(value.max(0)).unwrap_or(usize::MAX) }
|
||||
|
||||
fn mibs(input: usize) -> f64 {
|
||||
let whole = u32::try_from(input / (1024 * 1024)).unwrap_or(u32::MAX);
|
||||
let rem_kibs = u32::try_from((input / 1024) % 1024).unwrap_or_default();
|
||||
f64::from(whole) + f64::from(rem_kibs) / 1024.0
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn memory_usage() -> Option<String> {
|
||||
let stats = read_stats()?;
|
||||
|
||||
Some(format!(
|
||||
"reserved: {:.2} MiB\nreserved_peak: {:.2} MiB\ncommitted: {:.2} MiB\ncommitted_peak: \
|
||||
{:.2} MiB\npurged_total: {:.2} MiB\nreset_total: {:.2} MiB\n",
|
||||
mibs(non_neg_usize(stats.reserved.current)),
|
||||
mibs(non_neg_usize(stats.reserved.peak)),
|
||||
mibs(non_neg_usize(stats.committed.current)),
|
||||
mibs(non_neg_usize(stats.committed.peak)),
|
||||
mibs(non_neg_usize(stats.purged)),
|
||||
mibs(non_neg_usize(stats.reset)),
|
||||
))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn memory_usage_stats() -> Option<ArrayVec<(&'static str, usize), 6>> {
|
||||
let stats = read_stats()?;
|
||||
let mut out = ArrayVec::new();
|
||||
out.extend([
|
||||
("reserved", non_neg_usize(stats.reserved.current)),
|
||||
("reserved_peak", non_neg_usize(stats.reserved.peak)),
|
||||
("committed", non_neg_usize(stats.committed.current)),
|
||||
("committed_peak", non_neg_usize(stats.committed.peak)),
|
||||
]);
|
||||
|
||||
Some(out)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn memory_stats(opts: &str) -> Option<String> {
|
||||
const MAX_LENGTH: usize = 1_048_576;
|
||||
|
||||
if opts.contains('\0') {
|
||||
return None;
|
||||
}
|
||||
|
||||
if opts.contains('J') {
|
||||
let stats = MiMalloc::stats_json().ok()?;
|
||||
let json = String::from_utf8_lossy(stats.to_bytes());
|
||||
let end = json.floor_char_boundary(json.len().min(MAX_LENGTH));
|
||||
return json.get(..end).map(str::to_owned);
|
||||
}
|
||||
|
||||
let mut state = StatsPrintState {
|
||||
buf: String::new(),
|
||||
max_len: MAX_LENGTH,
|
||||
panic: None,
|
||||
};
|
||||
let opaque = ptr::from_mut(&mut state).cast::<c_void>();
|
||||
|
||||
// SAFETY: `state` remains live in this frame for the duration of
|
||||
// `mi_stats_print_out()`, which invokes `mi_stats_cb` synchronously.
|
||||
unsafe { ffi::mi_stats_print_out(Some(mi_stats_cb), opaque) };
|
||||
|
||||
if let Some(payload) = state.panic {
|
||||
panic::resume_unwind(payload);
|
||||
}
|
||||
|
||||
Some(state.buf)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn mi_stats_cb(msg: *const MiChar, arg: *mut c_void) {
|
||||
// SAFETY: `arg` points to `StatsPrintState` on the caller's stack.
|
||||
let Some(state) = (unsafe { arg.cast::<StatsPrintState>().as_mut() }) else {
|
||||
return;
|
||||
};
|
||||
|
||||
if state.panic.is_some() || msg.is_null() || state.buf.len() >= state.max_len {
|
||||
return;
|
||||
}
|
||||
|
||||
// SAFETY: mimalloc guarantees `msg` is a valid NUL-terminated C string.
|
||||
let msg = unsafe { CStr::from_ptr(msg.cast()) };
|
||||
|
||||
if let Err(err) = panic::catch_unwind(AssertUnwindSafe(|| {
|
||||
let msg = String::from_utf8_lossy(msg.to_bytes());
|
||||
let remaining = state.max_len.saturating_sub(state.buf.len());
|
||||
if msg.len() <= remaining {
|
||||
state.buf.push_str(msg.as_ref());
|
||||
} else {
|
||||
if let Some(prefix) = msg.get(..msg.floor_char_boundary(remaining)) {
|
||||
state.buf.push_str(prefix);
|
||||
}
|
||||
state.max_len = state.buf.len();
|
||||
}
|
||||
})) {
|
||||
state.panic = Some(err);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn trim_succeeds() { trim(None).expect("trim(None)"); }
|
||||
|
||||
#[test]
|
||||
fn non_neg_usize_clamps_negative_values() {
|
||||
assert_eq!(non_neg_usize(-1), 0, "expected -1 to clamp to 0");
|
||||
assert_eq!(non_neg_usize(i64::MIN), 0, "expected i64::MIN to clamp to 0");
|
||||
assert_eq!(non_neg_usize(0), 0, "expected 0 to remain 0");
|
||||
assert_eq!(non_neg_usize(4096), 4096, "expected positive value unchanged");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memory_usage_stats_reports_allocator_bytes() {
|
||||
let buf = std::hint::black_box(vec![0_u8; 64 * 1024]);
|
||||
let stats = memory_usage_stats().expect("memory_usage_stats");
|
||||
drop(buf);
|
||||
|
||||
let keys: Vec<_> = stats.iter().map(|&(key, _)| key).collect();
|
||||
assert_eq!(
|
||||
keys,
|
||||
["reserved", "reserved_peak", "committed", "committed_peak"],
|
||||
"unexpected stat keys"
|
||||
);
|
||||
|
||||
for (key, bytes) in stats {
|
||||
assert!(bytes > 0, "expected {key} > 0, got {bytes}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memory_usage_returns_allocator_summary() {
|
||||
let usage = memory_usage().expect("memory_usage");
|
||||
for expected in [
|
||||
"reserved:",
|
||||
"reserved_peak:",
|
||||
"committed:",
|
||||
"committed_peak:",
|
||||
"purged_total:",
|
||||
"reset_total:",
|
||||
"MiB",
|
||||
] {
|
||||
assert!(usage.contains(expected), "missing {expected:?} in usage:\n{usage}");
|
||||
}
|
||||
assert!(!usage.contains("current_rss:"), "unexpected current_rss in usage:\n{usage}");
|
||||
assert!(!usage.contains("peak_rss:"), "unexpected peak_rss in usage:\n{usage}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memory_stats_supports_text_json_and_rejects_nul() {
|
||||
assert!(memory_stats("invalid\0opts").is_none(), "expected NUL opts to return None");
|
||||
|
||||
for opts in ["", "abcdefghijklmnopqrstuvwxyz"] {
|
||||
let stats = memory_stats(opts).expect("memory_stats text");
|
||||
assert!(!stats.is_empty(), "expected non-empty stats for opts={opts:?}");
|
||||
assert!(!stats.starts_with('{'), "expected formatted text, got JSON:\n{stats}");
|
||||
assert!(stats.contains("reserved"), "missing reserved in stats:\n{stats}");
|
||||
assert!(stats.contains("committed"), "missing committed in stats:\n{stats}");
|
||||
}
|
||||
|
||||
let json = memory_stats("J").expect("memory_stats JSON");
|
||||
assert!(json.starts_with('{'), "expected JSON object, got:\n{json}");
|
||||
let parsed: serde_json::Value =
|
||||
serde_json::from_str(&json).expect("expected valid JSON from memory_stats(\"J\")");
|
||||
assert!(parsed.get("committed").is_some(), "expected committed field in JSON");
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -4,24 +4,24 @@
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
|
||||
pub mod je;
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
|
||||
pub(crate) use je::metric;
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
|
||||
pub use je::{memory_stats, memory_usage, memory_usage_stats, trim};
|
||||
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", not(feature = "jemalloc")))]
|
||||
pub mod hardened;
|
||||
#[cfg(all(
|
||||
not(target_env = "msvc"),
|
||||
feature = "hardened_malloc",
|
||||
not(feature = "jemalloc")
|
||||
))]
|
||||
pub use hardened::{memory_stats, memory_usage, memory_usage_stats, trim};
|
||||
// mimalloc
|
||||
#[cfg(all(feature = "mimalloc", feature = "jemalloc", not(target_env = "msvc")))]
|
||||
compile_error!("the `mimalloc` and `jemalloc` features are mutually exclusive");
|
||||
#[cfg(all(feature = "mimalloc", any(target_env = "msvc", not(feature = "jemalloc"))))]
|
||||
pub mod mimalloc;
|
||||
#[cfg(all(feature = "mimalloc", any(target_env = "msvc", not(feature = "jemalloc"))))]
|
||||
pub(crate) use mimalloc::metric;
|
||||
#[cfg(all(feature = "mimalloc", any(target_env = "msvc", not(feature = "jemalloc"))))]
|
||||
pub use mimalloc::{memory_stats, memory_usage, memory_usage_stats, trim};
|
||||
|
||||
#[cfg(any(
|
||||
target_env = "msvc",
|
||||
all(not(feature = "hardened_malloc"), not(feature = "jemalloc"))
|
||||
))]
|
||||
// default
|
||||
#[cfg(all(not(feature = "mimalloc"), any(target_env = "msvc", not(feature = "jemalloc"))))]
|
||||
pub mod default;
|
||||
#[cfg(any(
|
||||
target_env = "msvc",
|
||||
all(not(feature = "hardened_malloc"), not(feature = "jemalloc"))
|
||||
))]
|
||||
#[cfg(all(not(feature = "mimalloc"), any(target_env = "msvc", not(feature = "jemalloc"))))]
|
||||
pub(crate) use default::metric;
|
||||
#[cfg(all(not(feature = "mimalloc"), any(target_env = "msvc", not(feature = "jemalloc"))))]
|
||||
pub use default::{memory_stats, memory_usage, memory_usage_stats, trim};
|
||||
@@ -5,7 +5,7 @@ use figment::Figment;
|
||||
use ruma::{OwnedServerName, events::room::server_acl::RoomServerAclEventContent};
|
||||
|
||||
use super::DEPRECATED_KEYS;
|
||||
use crate::{Config, Err, Result, Server, debug, debug_info, debug_warn, error, warn};
|
||||
use crate::{Config, Err, Result, Server, debug, debug_info, error, warn};
|
||||
|
||||
/// Performs check() with additional checks specific to reloading old config
|
||||
/// with new config.
|
||||
@@ -43,13 +43,6 @@ pub fn check(config: &Config) -> Result {
|
||||
));
|
||||
}
|
||||
|
||||
if cfg!(all(feature = "hardened_malloc", feature = "jemalloc", not(target_env = "msvc"))) {
|
||||
debug_warn!(
|
||||
"hardened_malloc and jemalloc compile-time features are both enabled, this causes \
|
||||
jemalloc to be used."
|
||||
);
|
||||
}
|
||||
|
||||
if cfg!(not(unix)) && config.unix_socket_path.is_some() {
|
||||
return Err!(Config(
|
||||
"unix_socket_path",
|
||||
|
||||
+10
-7
@@ -195,7 +195,7 @@ pub struct Config {
|
||||
/// announcements or major updates. This is not an update check endpoint.
|
||||
///
|
||||
/// default: true
|
||||
#[serde(alias = "allow_check_for_updates", default = "true_fn")]
|
||||
#[serde(default = "true_fn")]
|
||||
pub allow_announcements_check: bool,
|
||||
|
||||
/// Set this to any float value to multiply continuwuity's in-memory LRU
|
||||
@@ -490,7 +490,7 @@ pub struct Config {
|
||||
#[serde(default = "default_ip_lookup_strategy")]
|
||||
pub ip_lookup_strategy: u8,
|
||||
|
||||
/// The preferred source to use for getting the real client IP.
|
||||
/// DEPRECATED: The preferred source to use for getting the real client IP.
|
||||
///
|
||||
/// Takes any of the following options:
|
||||
///
|
||||
@@ -509,9 +509,10 @@ pub struct Config {
|
||||
/// to set this header" check; if the header selected is present, it is
|
||||
/// used.
|
||||
///
|
||||
/// Ignored if `accepted_ip_sources` is set.
|
||||
/// Ignored if `accepted_ip_sources` is set. `accepted_ip_sources` is
|
||||
/// the preferred alternative.
|
||||
///
|
||||
/// If not set set, `direct` is used. Additionally, `direct` is used
|
||||
/// If not set, `direct` is used. Additionally, `direct` is used
|
||||
/// as a fallback if the chosen header is not found.
|
||||
#[serde(default)]
|
||||
pub request_ip_source: Option<String>,
|
||||
@@ -2993,11 +2994,16 @@ impl<'de, K: Hash + Eq + Clone> Deserialize<'de> for PerMinuteRatelimiter<K> {
|
||||
}
|
||||
|
||||
const DEPRECATED_KEYS: &[&str] = &[
|
||||
"allow_check_for_updates",
|
||||
"allow_moderators_to_view_redacted_content",
|
||||
"allow_sticky_events",
|
||||
"cache_capacity",
|
||||
"conduit_cache_capacity_modifier",
|
||||
"max_concurrent_requests",
|
||||
"otlp_protocol",
|
||||
"request_ip_source",
|
||||
"roomid_spacehierarchy_cache_capacity",
|
||||
"unredacted_content_max_age_secs",
|
||||
"well_known_client",
|
||||
"well_known_server",
|
||||
"well_known_support_page",
|
||||
@@ -3005,9 +3011,6 @@ const DEPRECATED_KEYS: &[&str] = &[
|
||||
"well_known_support_email",
|
||||
"well_known_support_mxid",
|
||||
"well_known.rtc_focus_server_urls",
|
||||
"allow_sticky_events",
|
||||
"allow_moderators_to_view_redacted_content",
|
||||
"unredacted_content_max_age_secs",
|
||||
];
|
||||
|
||||
impl Config {
|
||||
|
||||
@@ -45,6 +45,14 @@ impl Instruments {
|
||||
.with_boundaries(duration_buckets())
|
||||
.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| {
|
||||
meter
|
||||
.u64_histogram(name)
|
||||
@@ -55,11 +63,11 @@ impl Instruments {
|
||||
};
|
||||
|
||||
Self {
|
||||
federation_outgoing_request_duration: duration(
|
||||
federation_outgoing_request_duration: long_duration(
|
||||
"continuwuity.federation.outgoing.request.duration",
|
||||
"Duration of outgoing federation requests",
|
||||
),
|
||||
federation_incoming_transaction_duration: duration(
|
||||
federation_incoming_transaction_duration: long_duration(
|
||||
"continuwuity.federation.incoming.transaction.duration",
|
||||
"Time taken to process incoming federation transactions",
|
||||
),
|
||||
@@ -75,11 +83,13 @@ impl Instruments {
|
||||
federation_incoming_pdu_lag: meter
|
||||
.f64_histogram("continuwuity.federation.incoming.pdu.lag")
|
||||
.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_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,
|
||||
21600.0, 86400.0,
|
||||
])
|
||||
.build(),
|
||||
federation_incoming_edus: meter
|
||||
@@ -92,7 +102,7 @@ impl Instruments {
|
||||
"Time taken to handle an incoming federation EDU",
|
||||
),
|
||||
|
||||
sender_transaction_duration: duration(
|
||||
sender_transaction_duration: long_duration(
|
||||
"continuwuity.sender.transaction.duration",
|
||||
"Duration of outgoing transactions by destination type and outcome",
|
||||
),
|
||||
@@ -130,6 +140,12 @@ impl Instruments {
|
||||
#[must_use]
|
||||
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 register_process(meter: &Meter) {
|
||||
@@ -196,9 +212,13 @@ fn register_process(meter: &Meter) {
|
||||
}
|
||||
|
||||
fn register_allocator(meter: &Meter) {
|
||||
let Some((name, description)) = crate::alloc::metric() else {
|
||||
return;
|
||||
};
|
||||
|
||||
meter
|
||||
.u64_observable_gauge("continuwuity.jemalloc.memory")
|
||||
.with_description("jemalloc memory statistics, when built with jemalloc_stats")
|
||||
.u64_observable_gauge(name)
|
||||
.with_description(description)
|
||||
.with_unit("By")
|
||||
.with_callback(|observer| {
|
||||
for (kind, bytes) in crate::alloc::memory_usage_stats().into_iter().flatten() {
|
||||
|
||||
@@ -38,3 +38,23 @@ async fn renders_prometheus_names() {
|
||||
}
|
||||
assert!(!body.contains("otel_scope_name"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[cfg(all(feature = "mimalloc", any(target_env = "msvc", not(feature = "jemalloc"))))]
|
||||
async fn renders_mimalloc_memory_metric() {
|
||||
let (metrics, _provider) = metrics();
|
||||
let body = metrics.render().unwrap();
|
||||
|
||||
for expected in [
|
||||
"continuwuity_mimalloc_memory_bytes{kind=\"reserved\"}",
|
||||
"continuwuity_mimalloc_memory_bytes{kind=\"reserved_peak\"}",
|
||||
"continuwuity_mimalloc_memory_bytes{kind=\"committed\"}",
|
||||
"continuwuity_mimalloc_memory_bytes{kind=\"committed_peak\"}",
|
||||
] {
|
||||
assert!(body.contains(expected), "missing {expected:?} in:\n{body}");
|
||||
}
|
||||
assert!(
|
||||
!body.contains("continuwuity_jemalloc_memory_bytes"),
|
||||
"unexpected jemalloc metric in mimalloc build:\n{body}"
|
||||
);
|
||||
}
|
||||
+3
-4
@@ -70,7 +70,6 @@ standard = [
|
||||
]
|
||||
full = [
|
||||
"standard",
|
||||
# "hardened_malloc", # Conflicts with jemalloc
|
||||
"jemalloc_prof",
|
||||
"perf_measurements",
|
||||
"tokio_console",
|
||||
@@ -96,9 +95,6 @@ gzip_compression = [
|
||||
"conduwuit-router/gzip_compression",
|
||||
"conduwuit-service/gzip_compression",
|
||||
]
|
||||
hardened_malloc = [
|
||||
"conduwuit-core/hardened_malloc",
|
||||
]
|
||||
http3 = [
|
||||
"conduwuit-service/http3"
|
||||
]
|
||||
@@ -116,6 +112,9 @@ jemalloc = [
|
||||
"conduwuit-core/jemalloc",
|
||||
"conduwuit-service/jemalloc",
|
||||
]
|
||||
mimalloc = [
|
||||
"conduwuit-core/mimalloc",
|
||||
]
|
||||
jemalloc_prof = [
|
||||
"conduwuit-core/jemalloc_prof",
|
||||
]
|
||||
|
||||
+8
-11
@@ -26,18 +26,15 @@ pub(crate) fn init(
|
||||
|
||||
let mut builder = SdkMeterProvider::builder()
|
||||
.with_resource(resource)
|
||||
.with_view(|instrument: &Instrument| {
|
||||
(instrument.name() == metric::HTTP_SERVER_REQUEST_DURATION)
|
||||
.then(|| {
|
||||
Stream::builder()
|
||||
.with_aggregation(Aggregation::ExplicitBucketHistogram {
|
||||
boundaries: duration_buckets(),
|
||||
record_min_max: true,
|
||||
})
|
||||
.build()
|
||||
.ok()
|
||||
.with_view(|instrument: &Instrument| match instrument.name() {
|
||||
| metric::HTTP_SERVER_REQUEST_DURATION => Stream::builder()
|
||||
.with_aggregation(Aggregation::ExplicitBucketHistogram {
|
||||
boundaries: duration_buckets(),
|
||||
record_min_max: true,
|
||||
})
|
||||
.flatten()
|
||||
.build()
|
||||
.ok(),
|
||||
| _ => None,
|
||||
});
|
||||
|
||||
let registry = config
|
||||
|
||||
@@ -64,7 +64,7 @@ pub(crate) async fn handle(
|
||||
.server
|
||||
.metrics
|
||||
.requests_handle_active
|
||||
.fetch_add(1, Ordering::Relaxed),
|
||||
.load(Ordering::Relaxed),
|
||||
handled = %services
|
||||
.server
|
||||
.metrics
|
||||
@@ -81,7 +81,11 @@ async fn execute(
|
||||
next: axum::middleware::Next,
|
||||
parent: &Span,
|
||||
) -> Response {
|
||||
#[cfg(debug_assertions)]
|
||||
services
|
||||
.server
|
||||
.metrics
|
||||
.requests_handle_active
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
conduwuit::defer! {{
|
||||
_ = services.server
|
||||
.metrics
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#[cfg(feature = "console")]
|
||||
use std::io::IsTerminal;
|
||||
|
||||
use conduwuit::{Err, Result, debug, debug_info, error, info, warn};
|
||||
use conduwuit::{Err, Result, debug, debug_info, error, info};
|
||||
use ruma::events::room::message::RoomMessageEventContent;
|
||||
use tokio::time::{Duration, sleep};
|
||||
|
||||
@@ -15,7 +16,7 @@ impl super::Service {
|
||||
#[cfg(feature = "console")]
|
||||
if self.services.server.config.admin_console_automatic {
|
||||
if !std::io::stdin().is_terminal() {
|
||||
warn!("Console enabled without a tty available; Not enabling console");
|
||||
conduwuit::warn!("Console enabled without a tty available; Not enabling console");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,14 +112,27 @@ impl Service {
|
||||
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
|
||||
.server
|
||||
.metrics
|
||||
.instruments
|
||||
.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 {
|
||||
@@ -196,12 +209,7 @@ impl Service {
|
||||
.read_to_end(&mut content)
|
||||
.await?;
|
||||
|
||||
self.services
|
||||
.server
|
||||
.metrics
|
||||
.instruments
|
||||
.media_read_size
|
||||
.record(content.len().try_into().unwrap_or(u64::MAX), &[self.origin(mxc)]);
|
||||
self.record_read(mxc, content.len());
|
||||
|
||||
Ok(Some(FileMeta {
|
||||
content: Some(content),
|
||||
|
||||
@@ -44,6 +44,7 @@ impl super::Service {
|
||||
//TODO: Dangling metadata in database if creation fails
|
||||
let mut f = self.create_media_file(&key).await?;
|
||||
f.write_all(file).await?;
|
||||
self.record_write(mxc, file.len());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -66,13 +67,19 @@ impl super::Service {
|
||||
// 0, 0 because that's the original file
|
||||
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,
|
||||
| _ => match self.db.search_file_metadata(mxc, &Dim::default()).await {
|
||||
| Ok(metadata) => self.get_thumbnail_generate(mxc, &dim, metadata).await,
|
||||
| _ => Ok(None),
|
||||
},
|
||||
};
|
||||
|
||||
if let Ok(Some(FileMeta { content: Some(content), .. })) = &thumbnail {
|
||||
self.record_read(mxc, content.len());
|
||||
}
|
||||
|
||||
thumbnail
|
||||
}
|
||||
|
||||
/// Using saved thumbnail
|
||||
@@ -132,6 +139,7 @@ impl super::Service {
|
||||
|
||||
let mut f = self.create_media_file(&thumbnail_key).await?;
|
||||
f.write_all(&thumbnail_bytes).await?;
|
||||
self.record_write(mxc, thumbnail_bytes.len());
|
||||
|
||||
Ok(Some(into_filemeta(data, thumbnail_bytes)))
|
||||
}
|
||||
|
||||
@@ -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 conduwuit::{
|
||||
@@ -359,6 +359,7 @@ impl Service {
|
||||
&self,
|
||||
claims: &Claims,
|
||||
supplied_user_id: Option<OwnedUserId>,
|
||||
client_ip: &IpAddr,
|
||||
) -> Result<SessionCompletionStatus, &'static str> {
|
||||
let Some(OidcClient { config, .. }) = self.client.as_ref() else {
|
||||
return Err("Delegated authentication is not enabled on this server.");
|
||||
@@ -419,7 +420,7 @@ impl Service {
|
||||
// Create a new shadow user
|
||||
self.services
|
||||
.users
|
||||
.create_local_account(&user_id, None, None, None, None)
|
||||
.create_local_account(&user_id, None, None, Some(client_ip), None)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
error!("Failed to create a shadow user for {user_id}: {err}");
|
||||
|
||||
@@ -4,18 +4,16 @@ use conduwuit::{Err, Event, Pdu, Result, is_not_empty, utils::ReadyExt};
|
||||
use database::{Json, serialize_key};
|
||||
use futures::StreamExt;
|
||||
use ruma::{
|
||||
OwnedServerName, RoomId, UserId,
|
||||
CanonicalJsonObject, OwnedServerName, RoomId, UserId,
|
||||
api::federation::membership::RawStrippedState,
|
||||
events::{
|
||||
AnyStrippedStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType,
|
||||
StateEventType,
|
||||
GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType,
|
||||
direct::DirectEvent,
|
||||
room::{
|
||||
create::RoomCreateEventContent,
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
},
|
||||
serde::Raw,
|
||||
};
|
||||
use ruminuwuity::invite_permission_config::FilterLevel;
|
||||
|
||||
@@ -274,7 +272,7 @@ impl super::Service {
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
knocked_state: Option<Vec<Raw<AnyStrippedStateEvent>>>,
|
||||
knocked_state: Option<Vec<&CanonicalJsonObject>>,
|
||||
) {
|
||||
let userroom_id = (user_id, room_id);
|
||||
let userroom_id = serialize_key(userroom_id).expect("failed to serialize userroom_id");
|
||||
|
||||
@@ -6,6 +6,7 @@ use axum::{
|
||||
response::Redirect,
|
||||
routing::on,
|
||||
};
|
||||
use conduwuit_api::client_ip::ClientIp;
|
||||
use conduwuit_service::{
|
||||
oauth::grant::AuthorizationCodeResponse,
|
||||
oidc::{ClaimedLocalUser, SessionCompletionStatus},
|
||||
@@ -63,6 +64,7 @@ async fn route_complete(
|
||||
Expect(Query(query)): Expect<Query<AuthorizationCodeResponse>>,
|
||||
session_store: Session,
|
||||
user: User<true>,
|
||||
ClientIp(client_ip): ClientIp,
|
||||
PostForm(form): PostForm<LoginForm>,
|
||||
) -> Result {
|
||||
let user_id = user.into_session().map(|session| session.user_id);
|
||||
@@ -104,7 +106,10 @@ async fn route_complete(
|
||||
.await
|
||||
.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 } => {
|
||||
let supplied_user_id = if let Some(form) = form {
|
||||
@@ -163,7 +168,7 @@ async fn route_complete(
|
||||
|
||||
services
|
||||
.oidc
|
||||
.complete_session(&claims, supplied_user_id)
|
||||
.complete_session(&claims, supplied_user_id, &client_ip)
|
||||
.await
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user