mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-21 16:07:35 +00:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
351ed750b2 | ||
|
|
6174411bed | ||
|
|
629a12f124 | ||
|
|
aabf631f85 | ||
|
|
f81eee7710 | ||
|
|
7737510b5a | ||
|
|
5cc5bb6f52 | ||
|
|
b4f9462c7f | ||
|
|
b911b2e405 | ||
|
|
f75127843b | ||
|
|
e19ff4b3ce |
No files matched your search
Generated
+2
-1
@@ -4002,7 +4002,8 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "opentelemetry-instrumentation-tower"
|
||||
version = "0.19.0"
|
||||
source = "git+https://github.com/open-telemetry/opentelemetry-rust-contrib?rev=6bbbc337aab0bcf10d7799c3e5b5ced75920491a#6bbbc337aab0bcf10d7799c3e5b5ced75920491a"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e7006f3b1853d315462a7237c81eec3d7adfa5b70975a02b19e92d045bc22d7"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"http",
|
||||
|
||||
+1
-2
@@ -435,8 +435,7 @@ features = ["reqwest"]
|
||||
version = "0.33.1"
|
||||
|
||||
[workspace.dependencies.opentelemetry-instrumentation-tower]
|
||||
git = "https://github.com/open-telemetry/opentelemetry-rust-contrib"
|
||||
rev = "6bbbc337aab0bcf10d7799c3e5b5ced75920491a"
|
||||
version = "0.19.0"
|
||||
default-features = false
|
||||
features = ["axum"]
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Fixed Prometheus accounting for in-flight requests, federation PDU lag, latency buckets, and thumbnail sizes. Contributed by @eleboucher.
|
||||
@@ -1 +0,0 @@
|
||||
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.
|
||||
@@ -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\",http_route!~\".*/sync\"}[$__rate_interval])))",
|
||||
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\"}[$__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\",http_route!~\".*/sync\"}[$__rate_interval])))",
|
||||
"expr": "histogram_quantile(0.5, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\"}[$__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\",http_route!~\".*/sync\"}[$__rate_interval])))",
|
||||
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\"}[$__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\",http_route!~\".*/sync\"}[$__rate_interval])))",
|
||||
"expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket{instance=~\"$instance\"}[$__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 transaction arriving; affected by clock skew",
|
||||
"description": "Time between an accepted PDU's origin_server_ts and its arrival; affected by clock skew",
|
||||
"id": 21,
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
|
||||
Generated
+104
-131
@@ -16,21 +16,21 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/core": {
|
||||
"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==",
|
||||
"version": "1.11.3",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.3.tgz",
|
||||
"integrity": "sha512-zLpS5asjEb7lq8jYLq37N6XKaE41DIexlY1rF/z4/tIl3wo13Sqm28fRyfIsKZD+NZ8mM5RoKkpW/rBcuoSZSg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/wasi-threads": "2.2.0",
|
||||
"@emnapi/wasi-threads": "1.2.3",
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/runtime": {
|
||||
"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==",
|
||||
"version": "1.11.3",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz",
|
||||
"integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
@@ -39,9 +39,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/wasi-threads": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-2.2.0.tgz",
|
||||
"integrity": "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==",
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.3.tgz",
|
||||
"integrity": "sha512-ELEBe8PsLvvJ6QMr0zLt8ffvOHW/dc1m3CEzNMg7aJUv3bMaoDtw2TXyDAwkYBuroxxuHEwhRTLJSe5sya547g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
@@ -106,36 +106,33 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/wasm-runtime": {
|
||||
"version": "1.2.7",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.7.tgz",
|
||||
"integrity": "sha512-zJccwplOAbgfZju95IUHazLnx9RAPtPN2YGJXI6UbrgeaR9QfPjGrQL6ERkSAtnVCA4Q+83ApGyaX5zdpCaKkQ==",
|
||||
"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==",
|
||||
"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 || 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"
|
||||
"@emnapi/core": "^1.7.1",
|
||||
"@emnapi/runtime": "^1.7.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@rsbuild/core": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rsbuild/core/-/core-2.3.3.tgz",
|
||||
"integrity": "sha512-IdbBXZrIY16RxnQduXRrsRBQtJ/X7JkYESrk6D46WA918wrckYTBxE09vHvDxR+3JoCLE02vOm2NPBNxqaUw5A==",
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rsbuild/core/-/core-2.3.1.tgz",
|
||||
"integrity": "sha512-dv5tL7djb8ex5z4sqnDmUbd5PnGNr/CXuFfiMD4RkUsF1JEZZkGH8lc+QW4fqYQIHM7RTvcMUakgvwVU/O9WMw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rspack/core": "~2.3.3",
|
||||
"@swc/helpers": "^0.5.24"
|
||||
"@rspack/core": "~2.3.1",
|
||||
"@swc/helpers": "^0.5.23"
|
||||
},
|
||||
"bin": {
|
||||
"rsbuild": "bin/rsbuild.js"
|
||||
@@ -172,32 +169,32 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspack/binding": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding/-/binding-2.3.3.tgz",
|
||||
"integrity": "sha512-wwF++36a3rqYi0G9zj+rUavn/GIMzbzXehelGS1jkYeKPHyPXrVYwRHqwEKNKMD9z+FdW4YJKQcfFkPlHEiwUg==",
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding/-/binding-2.3.1.tgz",
|
||||
"integrity": "sha512-pfCJGBFNK2tnNnoDP6ZoTbOjxbKr1U2eGFDJ8bIuZQai4FBNhWQlKFmNup+X5K935XYRulZBomIBAL6GL6W2YQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optionalDependencies": {
|
||||
"@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"
|
||||
"@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"
|
||||
}
|
||||
},
|
||||
"node_modules/@rspack/binding-darwin-arm64": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -209,9 +206,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-darwin-x64": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-x64/-/binding-darwin-x64-2.3.3.tgz",
|
||||
"integrity": "sha512-6agI5XDoihay+84vzZgIwwpQQ3xBWbe2HTWBRc0n42LzynIj9h7Qv8CJzf1gSDV1Ts0jzDgAJCYUFJ6Ya5F6MA==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -223,16 +220,13 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-arm64-gnu": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -240,16 +234,13 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-arm64-musl": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -257,16 +248,13 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-ppc64-gnu": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -274,16 +262,13 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-riscv64-gnu": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -291,16 +276,13 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-riscv64-musl": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -308,16 +290,13 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-s390x-gnu": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -325,16 +304,13 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-x64-gnu": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -342,16 +318,13 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-linux-x64-musl": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -359,9 +332,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-wasm32-wasi": {
|
||||
"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==",
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/binding-wasm32-wasi/-/binding-wasm32-wasi-2.3.1.tgz",
|
||||
"integrity": "sha512-3dr6zjFaCK3A920ftCriSJkiRhEfhHtat7LtBdj6g0mcV5Rt+iealmli0vjeAvD0UdpE1u8EKWlfw82JLgFLSQ==",
|
||||
"cpu": [
|
||||
"wasm32"
|
||||
],
|
||||
@@ -369,15 +342,15 @@
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/core": "2.0.0-beta.3",
|
||||
"@emnapi/runtime": "2.0.0-beta.3",
|
||||
"@napi-rs/wasm-runtime": "1.2.7"
|
||||
"@emnapi/core": "1.11.3",
|
||||
"@emnapi/runtime": "1.11.3",
|
||||
"@napi-rs/wasm-runtime": "1.1.6"
|
||||
}
|
||||
},
|
||||
"node_modules/@rspack/binding-win32-arm64-msvc": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -389,9 +362,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-win32-ia32-msvc": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
@@ -403,9 +376,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/binding-win32-x64-msvc": {
|
||||
"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==",
|
||||
"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==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -417,13 +390,13 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@rspack/core": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/core/-/core-2.3.3.tgz",
|
||||
"integrity": "sha512-stAYr0SXf+ZFXFsWTv+Ljxoj/nQs2p7gX9V1kBwlO2IXlRAAhabLONYibT3ZeEGybx3kowrs7uJkcOQsuHgghw==",
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspack/core/-/core-2.3.1.tgz",
|
||||
"integrity": "sha512-9BWfaiEJLgLK9U53Q4WVruBZ19Mu/XWHXHEu0UFla4lUtH8Z+/ET2m044tiqbtyIgqQyG58fMrxHeVIAiXMXHg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rspack/binding": "2.3.3"
|
||||
"@rspack/binding": "2.3.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
@@ -458,17 +431,17 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/core": {
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.4.tgz",
|
||||
"integrity": "sha512-7OmP7ABDgQLSpVfpBHfpjqu4H3PGBGMyhLxF1crPQ48Q6MIWAVu77nw7cONn8AZa9GoVq0N/DoE3GEtgZzlu6w==",
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.3.tgz",
|
||||
"integrity": "sha512-qKa5c7zHO8cmhxkReURd3dN/ZRfHYnEztdIQ9hMuolaNzhSYo2A36XErUvLvbMf2EUM2AxfPYRQv+4Crfeq6pw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@mdx-js/mdx": "^3.1.1",
|
||||
"@mdx-js/react": "^3.1.1",
|
||||
"@rsbuild/core": "^2.3.3",
|
||||
"@rsbuild/core": "^2.2.14",
|
||||
"@rsbuild/plugin-react": "~2.1.1",
|
||||
"@rspress/shared": "2.1.4",
|
||||
"@rspress/shared": "2.1.3",
|
||||
"@shikijs/rehype": "^4.2.0",
|
||||
"@shikijs/transformers": "^4.2.0",
|
||||
"@types/mdast": "^4.0.4",
|
||||
@@ -512,9 +485,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/plugin-client-redirects": {
|
||||
"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==",
|
||||
"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==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -525,9 +498,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/plugin-sitemap": {
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.4.tgz",
|
||||
"integrity": "sha512-TObDTXgBKFAHEWEth47aehQSYtFfpIkqM4w14a0hUbPLkbu2AZ2cKnMzFTKK+W6I/3LN54scvfGYTL5CPQsDXw==",
|
||||
"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==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -538,13 +511,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/shared": {
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.4.tgz",
|
||||
"integrity": "sha512-SuQyVKn9xcQwkzfl+4bPBzX10gxbhCs9UupqSoPtxvyr9pMgSbXnlo3gxTPZXLzk5HUqZZ6tlIju25PVCEtYWA==",
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.3.tgz",
|
||||
"integrity": "sha512-VwJ7kgsTWVqHzSXQVHIUCsdMparmq9b/IDmTa3a6jMPl1zmm5Qg9M0eP4j8JXWoIS9n19XtCkQcZmMTFOPRy3A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rsbuild/core": "^2.3.3",
|
||||
"@rsbuild/core": "^2.2.14",
|
||||
"@shikijs/rehype": "^4.2.0",
|
||||
"@types/react": "^19.3.0",
|
||||
"mdast-util-mdx-jsx": "^3.2.1",
|
||||
@@ -699,9 +672,9 @@
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@tybys/wasm-util": {
|
||||
"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==",
|
||||
"version": "0.10.4",
|
||||
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz",
|
||||
"integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
|
||||
@@ -332,7 +332,6 @@ 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
|
||||
@@ -393,7 +392,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 = arrived.saturating_sub(ts);
|
||||
let lag = millis_since_unix_epoch().saturating_sub(ts);
|
||||
instruments
|
||||
.federation_incoming_pdu_lag
|
||||
.record(Duration::from_millis(lag).as_secs_f64(), &[]);
|
||||
|
||||
+142
-85
@@ -1,8 +1,6 @@
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
ops::Deref,
|
||||
ptr,
|
||||
ptr::null_mut,
|
||||
ptr::NonNull,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicPtr, Ordering},
|
||||
@@ -10,119 +8,178 @@ use std::{
|
||||
};
|
||||
|
||||
use super::Config;
|
||||
use crate::Result;
|
||||
use crate::{Result, SyncMutex};
|
||||
|
||||
/// The configuration manager is an indirection to reload the configuration for
|
||||
/// the server while it is running. In order to not burden or clutter the many
|
||||
/// callsites which query for configuration items, this object implements Deref
|
||||
/// for the actively loaded configuration.
|
||||
///
|
||||
/// Every installed `Arc<Config>` is kept at a stable heap address in `retired`
|
||||
/// for the entire lifetime of `Manager` (intentionally retaining prior configs
|
||||
/// across the rare, admin-triggered reloads until shutdown). Because
|
||||
/// `Deref::deref(&self)` ties the returned `&Arc<Config>` lifetime to `&self`,
|
||||
/// readers can perform a single `Acquire` load with no locking, no TLS, and no
|
||||
/// risk of dangling or aliasing UB across reloads.
|
||||
pub struct Manager {
|
||||
active: AtomicPtr<Config>,
|
||||
active: AtomicPtr<Arc<Config>>,
|
||||
/// Append-only owner of every `Box<Arc<Config>>` ever published to
|
||||
/// `active` (including the currently active config). Entries are only
|
||||
/// freed when `Manager` itself is dropped (`&mut self`), guaranteeing that
|
||||
/// any `&Arc<Config>` returned by `Deref::deref` remains valid and
|
||||
/// immutable for the lifetime of `self`.
|
||||
retired: SyncMutex<Vec<PinnedConfig>>,
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static INDEX: Cell<usize> = 0.into();
|
||||
static HANDLE: RefCell<Handles> = const {
|
||||
RefCell::new([const { None }; HISTORY])
|
||||
};
|
||||
/// Heap-pinned `Arc<Config>` stored as a raw `NonNull` rather than `Box` so
|
||||
/// moving it (e.g., when `Vec` reallocates) never retags or invalidates raw
|
||||
/// pointers previously published to `Manager::active`.
|
||||
struct PinnedConfig(NonNull<Arc<Config>>);
|
||||
|
||||
// SAFETY: `Arc<Config>` is `Send + Sync`, and `PinnedConfig` uniquely owns the
|
||||
// `Box<Arc<Config>>` allocation until it is dropped in `Manager::drop`.
|
||||
unsafe impl Send for PinnedConfig {}
|
||||
|
||||
impl PinnedConfig {
|
||||
fn new(config: Config) -> Self {
|
||||
let ptr = Box::into_raw(Box::new(Arc::new(config)));
|
||||
Self(NonNull::new(ptr).expect("Box::into_raw returned null"))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
const fn as_ptr(&self) -> *mut Arc<Config> { self.0.as_ptr() }
|
||||
}
|
||||
|
||||
type Handle = Option<Arc<Config>>;
|
||||
type Handles = [Handle; HISTORY];
|
||||
|
||||
const HISTORY: usize = 8;
|
||||
impl Drop for PinnedConfig {
|
||||
fn drop(&mut self) {
|
||||
// SAFETY: `self.0` was created via `Box::into_raw` in
|
||||
// `PinnedConfig::new` and is only dropped when `Manager` itself is
|
||||
// dropped (`&mut self`), after all borrows derived from `Deref::deref`
|
||||
// have ended.
|
||||
unsafe {
|
||||
drop(Box::from_raw(self.0.as_ptr()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Manager {
|
||||
pub(crate) fn new(config: Config) -> Self {
|
||||
let config = Arc::new(config);
|
||||
let pinned = PinnedConfig::new(config);
|
||||
let ptr = pinned.as_ptr();
|
||||
Self {
|
||||
active: AtomicPtr::new(Arc::into_raw(config).cast_mut()),
|
||||
active: AtomicPtr::new(ptr),
|
||||
retired: SyncMutex::new(vec![pinned]),
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the active configuration, returning prior configuration.
|
||||
#[tracing::instrument(skip_all, level = "info")]
|
||||
pub fn update(&self, config: Config) -> Result<Arc<Config>> {
|
||||
let config = Arc::new(config);
|
||||
let new = Arc::into_raw(config);
|
||||
let old = self.active.swap(new.cast_mut(), Ordering::AcqRel);
|
||||
let pinned = PinnedConfig::new(config);
|
||||
let new_ptr = pinned.as_ptr();
|
||||
|
||||
// SAFETY: The old active pointer was set using an Arc::into_raw().
|
||||
// We're obliged to reconstitute that into Arc otherwise it will leak.
|
||||
Ok(unsafe { Arc::from_raw(old) })
|
||||
}
|
||||
let mut retired = self.retired.lock();
|
||||
// Push before publishing to `active` so ownership is recorded even if
|
||||
// `Vec::push` were to unwind.
|
||||
retired.push(pinned);
|
||||
|
||||
fn load(&self, handle: &mut [Option<Arc<Config>>]) -> &'static Arc<Config> {
|
||||
let config = self.active.load(Ordering::Acquire);
|
||||
// `Release` publishes the initialized `Box<Arc<Config>>` to readers
|
||||
// performing `Acquire` loads in `Deref::deref`.
|
||||
let old_ptr = self.active.swap(new_ptr, Ordering::AcqRel);
|
||||
|
||||
// Branch taken after config reload or first access by this thread.
|
||||
if handle[INDEX.get()]
|
||||
.as_ref()
|
||||
.is_none_or(|handle| !ptr::eq(config, Arc::as_ptr(handle)))
|
||||
{
|
||||
INDEX.set(INDEX.get().wrapping_add(1).wrapping_rem(HISTORY));
|
||||
return load_miss(handle, INDEX.get(), config);
|
||||
}
|
||||
// SAFETY: `old_ptr` points to a `PinnedConfig` still owned by `retired`
|
||||
// and cannot be freed until `Manager` is dropped.
|
||||
let old = unsafe { Arc::clone(&*old_ptr) };
|
||||
|
||||
let config: &Arc<Config> = handle[INDEX.get()]
|
||||
.as_ref()
|
||||
.expect("handle was already cached for this thread");
|
||||
|
||||
// SAFETY: The caller should not hold multiple references at a time
|
||||
// directly into Config, as a subsequent reference might invalidate
|
||||
// the thread's cache causing another reference to dangle.
|
||||
//
|
||||
// This is a highly unusual pattern as most config values are copied by
|
||||
// value or used immediately without running overlap with another
|
||||
// value. Even if it does actually occur somewhere, the window of
|
||||
// danger is limited to the config being reloaded while the reference
|
||||
// is held and another access is made by the same thread into a
|
||||
// different config value. This is mitigated by creating a buffer
|
||||
// of old configs rather than discarding at the earliest opportunity;
|
||||
// the odds of this scenario are thus astronomical.
|
||||
unsafe { std::mem::transmute(config) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Manager {
|
||||
fn drop(&mut self) {
|
||||
let config = self.active.swap(null_mut(), Ordering::AcqRel);
|
||||
|
||||
// SAFETY: The active pointer was set using an Arc::into_raw(). We're
|
||||
// obliged to reconstitute that into Arc otherwise it will leak.
|
||||
unsafe { Arc::from_raw(config) };
|
||||
Ok(old)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Manager {
|
||||
type Target = Arc<Config>;
|
||||
|
||||
fn deref(&self) -> &Self::Target { HANDLE.with_borrow_mut(|handle| self.load(handle)) }
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
let ptr = self.active.load(Ordering::Acquire);
|
||||
|
||||
// SAFETY: `ptr` was initialized in `Manager::new` or published via
|
||||
// `Ordering::AcqRel` in `Manager::update` and points to a
|
||||
// `PinnedConfig` in `self.retired`. Entries in `self.retired` are never
|
||||
// removed or mutated until `Manager` is dropped (`&mut self`), so the
|
||||
// returned `&'self Arc<Config>` remains valid and immutable for the
|
||||
// entire borrow of `self`.
|
||||
unsafe { &*ptr }
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(
|
||||
name = "miss",
|
||||
level = "trace",
|
||||
skip_all,
|
||||
fields(%index, ?config)
|
||||
)]
|
||||
#[allow(clippy::transmute_ptr_to_ptr)]
|
||||
fn load_miss(
|
||||
handle: &mut [Option<Arc<Config>>],
|
||||
index: usize,
|
||||
config: *const Config,
|
||||
) -> &'static Arc<Config> {
|
||||
// SAFETY: The active pointer was set prior and always remains valid. We're
|
||||
// reconstituting the Arc here but as a new reference, so the count is
|
||||
// incremented. This instance will be cached in the thread-local.
|
||||
let config = unsafe {
|
||||
Arc::increment_strong_count(config);
|
||||
Arc::from_raw(config)
|
||||
};
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::thread;
|
||||
|
||||
// SAFETY: See the note on the transmute above. The caller should not hold
|
||||
// more than one reference at a time directly into Config, as the second
|
||||
// access might invalidate the thread's cache, dangling the reference to
|
||||
// the first.
|
||||
unsafe { std::mem::transmute(handle[index].insert(config)) }
|
||||
use super::*;
|
||||
|
||||
fn test_config(server_name: &str) -> Config {
|
||||
use figment::{
|
||||
Figment,
|
||||
providers::{Format, Toml},
|
||||
};
|
||||
|
||||
let raw = format!("server_name = \"{server_name}\"\ndatabase_path = \"/tmp\"\n");
|
||||
Figment::new()
|
||||
.merge(Toml::string(&raw))
|
||||
.extract()
|
||||
.expect("valid test config")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deref_survives_many_reloads() {
|
||||
let manager = Manager::new(test_config("initial.example"));
|
||||
let first: &Arc<Config> = &manager;
|
||||
let first_name: &str = first.server_name.as_str();
|
||||
|
||||
for i in 0..32 {
|
||||
let prev = manager
|
||||
.update(test_config(&format!("reload-{i}.example")))
|
||||
.expect("update succeeds");
|
||||
if i == 0 {
|
||||
assert_eq!(prev.server_name.as_str(), "initial.example");
|
||||
}
|
||||
}
|
||||
|
||||
// Original reference remains valid and unchanged after > HISTORY
|
||||
// reloads.
|
||||
assert_eq!(first_name, "initial.example");
|
||||
assert_eq!(manager.server_name.as_str(), "reload-31.example");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concurrent_reads_and_updates() {
|
||||
let manager = Manager::new(test_config("start.example"));
|
||||
|
||||
thread::scope(|s| {
|
||||
for _ in 0..4 {
|
||||
s.spawn(|| {
|
||||
for _ in 0..200 {
|
||||
let cfg: &Arc<Config> = &manager;
|
||||
assert!(cfg.server_name.as_str().ends_with(".example"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
s.spawn(|| {
|
||||
for i in 0..32 {
|
||||
let _ = manager
|
||||
.update(test_config(&format!("iter-{i}.example")))
|
||||
.expect("update succeeds");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reference_outlives_scoped_thread() {
|
||||
let manager = Manager::new(test_config("scoped.example"));
|
||||
let cfg_ref: &Arc<Config> = thread::scope(|s| s.spawn(|| &*manager).join().unwrap());
|
||||
assert_eq!(cfg_ref.server_name.as_str(), "scoped.example");
|
||||
}
|
||||
}
|
||||
@@ -45,14 +45,6 @@ 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)
|
||||
@@ -63,11 +55,11 @@ impl Instruments {
|
||||
};
|
||||
|
||||
Self {
|
||||
federation_outgoing_request_duration: long_duration(
|
||||
federation_outgoing_request_duration: duration(
|
||||
"continuwuity.federation.outgoing.request.duration",
|
||||
"Duration of outgoing federation requests",
|
||||
),
|
||||
federation_incoming_transaction_duration: long_duration(
|
||||
federation_incoming_transaction_duration: duration(
|
||||
"continuwuity.federation.incoming.transaction.duration",
|
||||
"Time taken to process incoming federation transactions",
|
||||
),
|
||||
@@ -83,13 +75,11 @@ 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 \
|
||||
transaction arriving",
|
||||
"Time between an accepted incoming PDU's origin_server_ts and its arrival",
|
||||
)
|
||||
.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
|
||||
@@ -102,7 +92,7 @@ impl Instruments {
|
||||
"Time taken to handle an incoming federation EDU",
|
||||
),
|
||||
|
||||
sender_transaction_duration: long_duration(
|
||||
sender_transaction_duration: duration(
|
||||
"continuwuity.sender.transaction.duration",
|
||||
"Duration of outgoing transactions by destination type and outcome",
|
||||
),
|
||||
@@ -140,12 +130,6 @@ 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) {
|
||||
|
||||
+30
-4
@@ -22,11 +22,24 @@ macro_rules! mod_dtor {
|
||||
#[macro_export]
|
||||
macro_rules! mod_init {
|
||||
($body:block) => {
|
||||
#[cfg(not(all(target_family = "unix", not(target_vendor = "apple"))))]
|
||||
compile_error!("conduwuit_mods (mod_init!) requires an ELF Unix target");
|
||||
|
||||
#[used]
|
||||
#[cfg_attr(target_family = "unix", unsafe(link_section = ".init_array"))]
|
||||
// SAFETY: `.init_array` is the standard ELF constructor pointer table;
|
||||
// the dynamic loader invokes `_mod_init` before `main()` or on `dlopen`.
|
||||
#[cfg_attr(
|
||||
all(target_family = "unix", not(target_vendor = "apple")),
|
||||
unsafe(link_section = ".init_array")
|
||||
)]
|
||||
static MOD_INIT: unsafe extern "C" fn() = { _mod_init };
|
||||
|
||||
#[cfg_attr(target_family = "unix", unsafe(link_section = ".text.startup"))]
|
||||
// SAFETY: `.text.startup` is the standard ELF text subsection for
|
||||
// initialization functions.
|
||||
#[cfg_attr(
|
||||
all(target_family = "unix", not(target_vendor = "apple")),
|
||||
unsafe(link_section = ".text.startup")
|
||||
)]
|
||||
unsafe extern "C" fn _mod_init() -> () $body
|
||||
};
|
||||
}
|
||||
@@ -34,11 +47,24 @@ macro_rules! mod_init {
|
||||
#[macro_export]
|
||||
macro_rules! mod_fini {
|
||||
($body:block) => {
|
||||
#[cfg(not(all(target_family = "unix", not(target_vendor = "apple"))))]
|
||||
compile_error!("conduwuit_mods (mod_fini!) requires an ELF Unix target");
|
||||
|
||||
#[used]
|
||||
#[cfg_attr(target_family = "unix", unsafe(link_section = ".fini_array"))]
|
||||
// SAFETY: `.fini_array` is the standard ELF destructor pointer table;
|
||||
// the dynamic loader invokes `_mod_fini` on `dlclose` or process teardown.
|
||||
#[cfg_attr(
|
||||
all(target_family = "unix", not(target_vendor = "apple")),
|
||||
unsafe(link_section = ".fini_array")
|
||||
)]
|
||||
static MOD_FINI: unsafe extern "C" fn() = { _mod_fini };
|
||||
|
||||
#[cfg_attr(target_family = "unix", unsafe(link_section = ".text.startup"))]
|
||||
// SAFETY: `.text.exit` / `.text.startup` is a standard ELF text
|
||||
// subsection for teardown/initialization functions.
|
||||
#[cfg_attr(
|
||||
all(target_family = "unix", not(target_vendor = "apple")),
|
||||
unsafe(link_section = ".text.startup")
|
||||
)]
|
||||
unsafe extern "C" fn _mod_fini() -> () $body
|
||||
};
|
||||
}
|
||||
+25
-7
@@ -13,11 +13,21 @@ pub struct Module {
|
||||
}
|
||||
|
||||
impl Module {
|
||||
pub fn from_name(name: &str) -> Result<Self> { Self::from_path(path::from_name(name)?) }
|
||||
/// # Safety
|
||||
/// See [`new::from_name`]: loads a shared library via `dlopen(3)` and runs
|
||||
/// its initialization routines.
|
||||
pub unsafe fn from_name(name: &str) -> Result<Self> {
|
||||
// SAFETY: Upheld by caller.
|
||||
unsafe { Self::from_path(path::from_name(name)?) }
|
||||
}
|
||||
|
||||
pub fn from_path(path: OsString) -> Result<Self> {
|
||||
/// # Safety
|
||||
/// See [`new::from_path`]: loads a shared library via `dlopen(3)` and runs
|
||||
/// its initialization routines.
|
||||
pub unsafe fn from_path(path: OsString) -> Result<Self> {
|
||||
Ok(Self {
|
||||
handle: Some(new::from_path(&path)?),
|
||||
// SAFETY: Upheld by caller.
|
||||
handle: Some(unsafe { new::from_path(&path)? }),
|
||||
loaded: SystemTime::now(),
|
||||
path,
|
||||
})
|
||||
@@ -38,16 +48,24 @@ impl Module {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get<Prototype>(&self, name: &str) -> Result<Symbol<Prototype>> {
|
||||
/// Look up a symbol in this module via `dlsym(3)`.
|
||||
///
|
||||
/// # Safety
|
||||
/// `Prototype` is not checked against the symbol's actual type or ABI in
|
||||
/// the loaded shared library. The caller must ensure `name` refers to a
|
||||
/// symbol whose type, calling convention, and ABI exactly match
|
||||
/// `Prototype`.
|
||||
pub unsafe fn get<Prototype>(&self, name: &str) -> Result<Symbol<'_, Prototype>> {
|
||||
let cname = CString::new(name.to_owned()).expect("terminated string from provided name");
|
||||
let handle = self
|
||||
.handle
|
||||
.as_ref()
|
||||
.expect("backing library loaded by this instance");
|
||||
|
||||
// SAFETY: Calls dlsym(3) on unix platforms. This might not have to be
|
||||
// unsafe if wrapped in libloading with_dlerror().
|
||||
let sym = unsafe { handle.get::<Prototype>(cname.as_bytes()) };
|
||||
// SAFETY: Caller guarantees `Prototype` matches the symbol's actual
|
||||
// type and ABI. Passing `as_bytes_with_nul()` avoids a redundant copy
|
||||
// inside `libloading`.
|
||||
let sym = unsafe { handle.get::<Prototype>(cname.as_bytes_with_nul()) };
|
||||
let sym = sym.expect("symbol found; binding successful");
|
||||
|
||||
Ok(sym)
|
||||
|
||||
+13
-5
@@ -5,14 +5,22 @@ use crate::{Err, Result};
|
||||
|
||||
const OPEN_FLAGS: i32 = libloading::os::unix::RTLD_LAZY | libloading::os::unix::RTLD_GLOBAL;
|
||||
|
||||
pub fn from_name(name: &str) -> Result<Library> {
|
||||
/// # Safety
|
||||
/// Loads a shared library via `dlopen(3)`, which executes the library's
|
||||
/// initialization routines (`.init_array` / constructors). The caller must
|
||||
/// ensure the resolved module is trusted and ABI-compatible with this binary.
|
||||
pub unsafe fn from_name(name: &str) -> Result<Library> {
|
||||
let path = path::from_name(name)?;
|
||||
from_path(&path)
|
||||
// SAFETY: Upheld by caller.
|
||||
unsafe { from_path(&path) }
|
||||
}
|
||||
|
||||
pub fn from_path(path: &OsStr) -> Result<Library> {
|
||||
//SAFETY: Calls dlopen(3) on unix platforms. This might not have to be
|
||||
// unsafe if wrapped in with_dlerror.
|
||||
/// # Safety
|
||||
/// Loads a shared library via `dlopen(3)`, which executes the library's
|
||||
/// initialization routines (`.init_array` / constructors). The caller must
|
||||
/// ensure `path` points to a trusted, ABI-compatible shared library.
|
||||
pub unsafe fn from_path(path: &OsStr) -> Result<Library> {
|
||||
// SAFETY: Caller guarantees `path` is a trusted, ABI-compatible library.
|
||||
let lib = unsafe { Library::open(Some(path), OPEN_FLAGS) };
|
||||
if let Err(e) = lib {
|
||||
let name = path::to_name(path)?;
|
||||
|
||||
+47
-3
@@ -62,14 +62,28 @@ macro_rules! validated {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::as_conversions)]
|
||||
#[allow(clippy::as_conversions, clippy::cast_possible_truncation, clippy::cast_sign_loss)]
|
||||
pub fn usize_from_f64(val: f64) -> Result<usize, Error> {
|
||||
// Exclusive upper bound for values whose truncation fits in `usize`.
|
||||
// Note that `usize::MAX as f64` rounds up to 2^64 on 64-bit targets, so a
|
||||
// strict `<` check against 2^(usize::BITS) rejects all out-of-range values
|
||||
// on both 32-bit and 64-bit targets.
|
||||
#[allow(clippy::cast_precision_loss)]
|
||||
const MAX_USIZE_EXCLUSIVE: f64 = (1_u128 << usize::BITS) as f64;
|
||||
|
||||
if !val.is_finite() {
|
||||
return Err!(Arithmetic("Converting non-finite float to unsigned integer"));
|
||||
}
|
||||
|
||||
if val < 0.0 {
|
||||
return Err!(Arithmetic("Converting negative float to unsigned integer"));
|
||||
}
|
||||
|
||||
//SAFETY: <https://doc.rust-lang.org/std/primitive.f64.html#method.to_int_unchecked>
|
||||
Ok(unsafe { val.to_int_unchecked::<usize>() })
|
||||
if val >= MAX_USIZE_EXCLUSIVE {
|
||||
return Err!(Arithmetic("Converting out-of-range float to unsigned integer"));
|
||||
}
|
||||
|
||||
Ok(val as usize)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -111,3 +125,33 @@ fn try_into_err<Dst: TryFrom<Src>, Src>(e: <Dst as TryFrom<Src>>::Error) -> Erro
|
||||
|
||||
#[inline]
|
||||
pub fn clamp<T: Ord>(val: T, min: T, max: T) -> T { cmp::min(cmp::max(val, min), max) }
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn usize_from_f64_valid() {
|
||||
assert_eq!(usize_from_f64(0.0).unwrap(), 0);
|
||||
assert_eq!(usize_from_f64(-0.0).unwrap(), 0);
|
||||
assert_eq!(usize_from_f64(42.9).unwrap(), 42);
|
||||
assert_eq!(usize_from_f64(1_048_576.0).unwrap(), 1_048_576);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn usize_from_f64_rejects_invalid() {
|
||||
usize_from_f64(-1.0).unwrap_err();
|
||||
usize_from_f64(-0.5).unwrap_err();
|
||||
usize_from_f64(f64::NAN).unwrap_err();
|
||||
usize_from_f64(f64::INFINITY).unwrap_err();
|
||||
usize_from_f64(f64::NEG_INFINITY).unwrap_err();
|
||||
usize_from_f64(1e30).unwrap_err();
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
{
|
||||
// `usize::MAX as f64` rounds up to 2^64, which is out of range.
|
||||
#[allow(clippy::as_conversions, clippy::cast_precision_loss)]
|
||||
let rounded_max = usize::MAX as f64;
|
||||
usize_from_f64(rounded_max).unwrap_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::convert::Infallible;
|
||||
|
||||
use super::{DebugInspect, Result};
|
||||
use crate::error;
|
||||
use super::Result;
|
||||
|
||||
pub trait UnwrapInfallible<T> {
|
||||
fn unwrap_infallible(self) -> T;
|
||||
@@ -10,8 +9,7 @@ pub trait UnwrapInfallible<T> {
|
||||
impl<T> UnwrapInfallible<T> for Result<T, Infallible> {
|
||||
#[inline]
|
||||
fn unwrap_infallible(self) -> T {
|
||||
// SAFETY: Branchless unwrap for errors that can never happen. In debug
|
||||
// mode this is asserted.
|
||||
unsafe { self.debug_inspect_err(error::infallible).unwrap_unchecked() }
|
||||
let Ok(val) = self;
|
||||
val
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,12 @@ impl<'a> From<&'a str> for &'a Unquoted {
|
||||
fn from(s: &'a str) -> &'a Unquoted {
|
||||
let s: &'a str = s.unquote_infallible();
|
||||
|
||||
//SAFETY: This is a pattern I lifted from ruma-identifiers for
|
||||
// strong-type strs by wrapping in a tuple-struct.
|
||||
#[allow(clippy::transmute_ptr_to_ptr)]
|
||||
// SAFETY: `Unquoted` is `#[repr(transparent)]` over `str`, so
|
||||
// `*const str` and `*const Unquoted` have identical layout and
|
||||
// metadata, and the returned reference preserves lifetime `'a`.
|
||||
#[allow(clippy::as_conversions)]
|
||||
unsafe {
|
||||
std::mem::transmute(s)
|
||||
&*(std::ptr::from_ref::<str>(s) as *const Unquoted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,21 +120,13 @@ pub fn cores_available() -> impl Iterator<Item = Id> { from_mask(*CORES_AVAILABL
|
||||
pub fn getcpu() -> Result<usize> {
|
||||
use crate::{Error, utils::math};
|
||||
|
||||
// SAFETY: This is part of an interface with many low-level calls taking
|
||||
// many raw params, but it's unclear why this specific call is unsafe.
|
||||
// Nevertheless the value obtained here is semantically unsafe because it
|
||||
// can change on the instruction boundary trailing its own acquisition and
|
||||
// also any other time.
|
||||
// SAFETY: `sched_getcpu(2)` takes no pointers and has no preconditions.
|
||||
// Note that it may still return -1 with errno set (e.g. under seccomp
|
||||
// filters or kernels without getcpu support), so the error branch below
|
||||
// must remain live.
|
||||
let ret: i32 = unsafe { libc::sched_getcpu() };
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
// SAFETY: On modern linux systems with a vdso if we can optimize away the branch checking
|
||||
// for error (see getcpu(2)) then this system call becomes a memory access.
|
||||
unsafe {
|
||||
std::hint::assert_unchecked(ret >= 0);
|
||||
};
|
||||
|
||||
if ret == -1 {
|
||||
if ret < 0 {
|
||||
return Err(Error::from_errno());
|
||||
}
|
||||
|
||||
|
||||
@@ -472,17 +472,5 @@ impl<'a, 'de: 'a> de::MapAccess<'de> for &'a mut Deserializer<'de> {
|
||||
}
|
||||
}
|
||||
|
||||
// activate when stable; too soon now
|
||||
//#[cfg(debug_assertions)]
|
||||
#[inline]
|
||||
fn deserialize_str(input: &[u8]) -> Result<&str> { string::str_from_bytes(input) }
|
||||
|
||||
//#[cfg(not(debug_assertions))]
|
||||
#[cfg(disable)]
|
||||
#[inline]
|
||||
fn deserialize_str(input: &[u8]) -> Result<&str> {
|
||||
// SAFETY: Strings were written by the serializer to the database. Assuming
|
||||
// no database corruption, the string will be valid. Database corruption is
|
||||
// detected via rocksdb checksums.
|
||||
unsafe { std::str::from_utf8_unchecked(input) }
|
||||
}
|
||||
@@ -46,6 +46,10 @@ use crate::{Engine, watchers::Watchers};
|
||||
pub struct Map {
|
||||
name: &'static str,
|
||||
watchers: Watchers,
|
||||
/// SAFETY / DROP ORDER: `cf` holds a lifetime-erased RocksDB column family
|
||||
/// handle (see `open::open`) and MUST be declared before `db` so that the
|
||||
/// handle is destroyed before `Engine` (and the underlying RocksDB `DB`)
|
||||
/// can be dropped.
|
||||
cf: Arc<ColumnFamily>,
|
||||
db: Arc<Engine>,
|
||||
read_options: ReadOptions,
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use rocksdb::ColumnFamily;
|
||||
use rocksdb::{BoundColumnFamily, ColumnFamily};
|
||||
|
||||
use crate::Engine;
|
||||
|
||||
pub(super) fn open(db: &Arc<Engine>, name: &str) -> Arc<ColumnFamily> {
|
||||
// Compile-time guard: `BoundColumnFamily` and `ColumnFamily` are both
|
||||
// `#[repr(Rust)]` in `rust-rocksdb`, so fail compilation if their size or
|
||||
// alignment ever diverge.
|
||||
const {
|
||||
assert!(
|
||||
size_of::<BoundColumnFamily<'_>>() == size_of::<ColumnFamily>(),
|
||||
"BoundColumnFamily and ColumnFamily must have identical size"
|
||||
);
|
||||
assert!(
|
||||
align_of::<BoundColumnFamily<'_>>() == align_of::<ColumnFamily>(),
|
||||
"BoundColumnFamily and ColumnFamily must have identical alignment"
|
||||
);
|
||||
}
|
||||
|
||||
let bounded_arc = db.cf(name);
|
||||
let bounded_ptr = Arc::into_raw(bounded_arc);
|
||||
let cf_ptr = bounded_ptr.cast::<ColumnFamily>();
|
||||
|
||||
@@ -12,6 +12,17 @@ impl super::Map {
|
||||
/// Iterate key-value entries in the map from the beginning.
|
||||
///
|
||||
/// - Result is deserialized
|
||||
///
|
||||
/// # Unsoundness
|
||||
/// Because Rust's `Stream` trait does not support lending items tied to
|
||||
/// `&mut self`, `stream::slice_longevity` unsafely extends the lifetime of
|
||||
/// raw RocksDB iterator slices to `'a` (the borrow of `Arc<Map>`). As a
|
||||
/// consequence, borrowed deserialized types (e.g. `&str`, `&UserId`,
|
||||
/// `&[u8]`) reference the underlying RocksDB cursor buffer and are
|
||||
/// invalidated on the next poll of the stream. Do not hold borrowed items
|
||||
/// across polls (e.g. via `collect()`, `ready_chunks()`, `peekable()`,
|
||||
/// `buffered()`, `buffer_unordered()`, `broadband`, or `wideband`) without
|
||||
/// converting them to owned values first.
|
||||
pub fn stream<'a, K, V>(
|
||||
self: &'a Arc<Self>,
|
||||
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send
|
||||
|
||||
+23
-11
@@ -54,8 +54,14 @@ pub(crate) struct Get {
|
||||
/// Note: only initial seek is supported at this time on the assumption rocksdb
|
||||
/// prefetching prevents mid-iteration polls from blocking on I/O.
|
||||
pub(crate) struct Seek {
|
||||
pub(crate) map: Arc<Map>,
|
||||
/// SAFETY / DROP ORDER: `state` wraps a RocksDB
|
||||
/// `DBRawIteratorWithThreadMode` referencing `map.db.db` whose lifetime has
|
||||
/// been erased to `'static`. `state` MUST be declared before `map` so the
|
||||
/// iterator is destroyed before `map` (and potentially the last
|
||||
/// `Arc<Engine>`) can be dropped if `Seek` is dropped early (e.g. on
|
||||
/// cancellation or queue closure).
|
||||
pub(crate) state: stream::State<'static>,
|
||||
pub(crate) map: Arc<Map>,
|
||||
pub(crate) dir: Direction,
|
||||
pub(crate) key: Option<KeyBuf>,
|
||||
pub(crate) res: Option<ResultSender<stream::State<'static>>>,
|
||||
@@ -416,24 +422,30 @@ impl Drop for Pool {
|
||||
}
|
||||
|
||||
fn into_send_get(result: BatchResult<'_>) -> BatchResult<'static> {
|
||||
// SAFETY: Necessary to send the Handle (rust_rocksdb::PinnableSlice)
|
||||
// through the channel. The lifetime on the handle is a device by
|
||||
// rust-rocksdb to associate a database lifetime with its assets. The
|
||||
// Handle must be dropped before the database is dropped.
|
||||
// SAFETY: Necessary to send `Handle` (which wraps
|
||||
// `rocksdb::DBPinnableSlice`) through the oneshot channel. The lifetime on
|
||||
// `Handle` ties it to the RocksDB `DB` instance; callers of `execute_get`
|
||||
// borrow `&self.db.pool` (which is owned by `Engine`), ensuring the
|
||||
// received `BatchResult<'_>` cannot outlive the database.
|
||||
unsafe { std::mem::transmute(result) }
|
||||
}
|
||||
|
||||
fn into_recv_get<'a>(result: BatchResult<'static>) -> BatchResult<'a> {
|
||||
// SAFETY: This is to receive the Handle from the channel.
|
||||
// SAFETY: Shrinking the erased `'static` lifetime back to `'a` (borrowed
|
||||
// from `&self.db.pool`). `SmallVec<A>` is invariant over `A`, so this
|
||||
// cannot be done via implicit covariance.
|
||||
unsafe { std::mem::transmute(result) }
|
||||
}
|
||||
|
||||
pub(crate) fn into_send_seek(result: stream::State<'_>) -> stream::State<'static> {
|
||||
// SAFETY: Necessary to send the State through the channel; see above.
|
||||
// SAFETY: Necessary to send `stream::State` through the pool channel.
|
||||
// While in flight on the queue, `Seek` owns an `Arc<Map>` (declared after
|
||||
// `state` so `state` drops first on early cancellation); once received back
|
||||
// from `execute_iter`, the lifetime is shrunk via `into_recv_seek` to the
|
||||
// caller's borrow of `&self.db.pool` (and `&'a Arc<Map>`), ensuring the
|
||||
// returned `stream::State<'_>` cannot outlive the database.
|
||||
unsafe { std::mem::transmute(result) }
|
||||
}
|
||||
|
||||
fn into_recv_seek(result: stream::State<'static>) -> stream::State<'static> {
|
||||
// SAFETY: This is to receive the State from the channel; see above.
|
||||
unsafe { std::mem::transmute(result) }
|
||||
}
|
||||
#[inline]
|
||||
const fn into_recv_seek<'a>(result: stream::State<'static>) -> stream::State<'a> { result }
|
||||
+14
-16
@@ -133,22 +133,20 @@ fn keyval_longevity<'a, 'b: 'a>(item: KeyVal<'a>) -> KeyVal<'b> {
|
||||
}
|
||||
|
||||
fn slice_longevity<'a, 'b: 'a>(item: &'a Slice) -> &'b Slice {
|
||||
// SAFETY: The lifetime of the data returned by the rocksdb cursor is only
|
||||
// valid between each movement of the cursor. It is hereby unsafely
|
||||
// extended to match the lifetime of the cursor itself. This is due to the
|
||||
// limitation of the Stream trait where the Item is incapable of conveying
|
||||
// a lifetime; this is due to GAT's being unstable during its development.
|
||||
// This unsafety can be removed as soon as this limitation is addressed by
|
||||
// an upcoming version.
|
||||
// SAFETY: the lifetime of the data returned by
|
||||
// the RocksDB cursor is only valid until the next movement of the cursor,
|
||||
// but is unsafely extended here to match the lifetime `'b` of the `Map`
|
||||
// borrow because `futures::Stream` is not a lending stream.
|
||||
//
|
||||
// We have done our best to mitigate the implications of this in conjunction
|
||||
// with the deserialization API such that borrows being held across
|
||||
// movements of the cursor do not happen accidentally. The compiler will
|
||||
// still error when values herein produced try to leave a closure passed to
|
||||
// a StreamExt API. But escapes can happen if you explicitly and
|
||||
// intentionally attempt it, and there will be no compiler error or
|
||||
// warning. This is primarily the case with calling collect() without a
|
||||
// preceding map(ToOwned::to_owned). A collection of references here is
|
||||
// illegal, but this will not be enforced by the compiler.
|
||||
// Callers MUST NOT hold borrowed items (or borrowed deserialized views such
|
||||
// as `&str`, `&UserId`, or `&[u8]`) across subsequent polls of the stream —
|
||||
// in particular, never call `collect()`, `ready_chunks()`, `peekable()`,
|
||||
// `buffered()`, `buffer_unordered()`, `broadband`, or `wideband` on a
|
||||
// stream yielding borrowed references without first converting items to
|
||||
// owned values (e.g. `map(ToOwned::to_owned)`). The compiler does NOT
|
||||
// reject such escapes when items borrow from `'b`.
|
||||
//
|
||||
// TODO: Fix this, it is old code and language changes may have made it
|
||||
// unnecessary
|
||||
unsafe { std::mem::transmute(item) }
|
||||
}
|
||||
@@ -1,28 +1,12 @@
|
||||
use conduwuit::Result;
|
||||
use rocksdb::{Direction, ErrorKind, IteratorMode};
|
||||
|
||||
//#[cfg(debug_assertions)]
|
||||
macro_rules! unhandled {
|
||||
($msg:literal) => {
|
||||
unimplemented!($msg)
|
||||
};
|
||||
}
|
||||
|
||||
// activate when stable; we're not ready for this yet
|
||||
#[cfg(disable)] // #[cfg(not(debug_assertions))]
|
||||
macro_rules! unhandled {
|
||||
($msg:literal) => {
|
||||
// SAFETY: Eliminates branches for serializing and deserializing types never
|
||||
// encountered in the codebase. This can promote optimization and reduce
|
||||
// codegen. The developer must verify for every invoking callsite that the
|
||||
// unhandled type is in no way involved and could not possibly be
|
||||
// encountered.
|
||||
unsafe {
|
||||
std::hint::unreachable_unchecked();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use unhandled;
|
||||
|
||||
#[inline]
|
||||
|
||||
+11
-8
@@ -26,15 +26,18 @@ pub(crate) fn init(
|
||||
|
||||
let mut builder = SdkMeterProvider::builder()
|
||||
.with_resource(resource)
|
||||
.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,
|
||||
.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()
|
||||
})
|
||||
.build()
|
||||
.ok(),
|
||||
| _ => None,
|
||||
.flatten()
|
||||
});
|
||||
|
||||
let registry = config
|
||||
|
||||
+15
-4
@@ -42,7 +42,10 @@ pub(crate) async fn run(server: &Arc<Server>, starts: bool) -> Result<(bool, boo
|
||||
let main_lock = server.mods.read().await;
|
||||
let main_mod = (*main_lock).last().expect("main module loaded");
|
||||
if starts {
|
||||
let start = main_mod.get::<StartFuncProto>("start")?;
|
||||
// SAFETY: `conduwuit_router` exports `#[unsafe(no_mangle)] pub extern
|
||||
// "Rust" fn start` with signature matching `StartFuncProto`, compiled
|
||||
// with the same toolchain and flags.
|
||||
let start = unsafe { main_mod.get::<StartFuncProto>("start")? };
|
||||
match start(&server.server).await {
|
||||
| Ok(services) => server.services.lock().await.insert(services),
|
||||
| Err(error) => {
|
||||
@@ -54,7 +57,10 @@ pub(crate) async fn run(server: &Arc<Server>, starts: bool) -> Result<(bool, boo
|
||||
|
||||
server.server.stopping.store(false, Ordering::Release);
|
||||
|
||||
let run = main_mod.get::<RunFuncProto>("run")?;
|
||||
// SAFETY: `conduwuit_router` exports `#[unsafe(no_mangle)] pub extern
|
||||
// "Rust" fn run` with signature matching `RunFuncProto`, compiled with the
|
||||
// same toolchain and flags.
|
||||
let run = unsafe { main_mod.get::<RunFuncProto>("run")? };
|
||||
if let Err(error) = run(server
|
||||
.services
|
||||
.lock()
|
||||
@@ -72,7 +78,10 @@ pub(crate) async fn run(server: &Arc<Server>, starts: bool) -> Result<(bool, boo
|
||||
let stops = !reloads || stale_from_mods(&main_lock)? <= restart_thresh();
|
||||
let starts = reloads && stops;
|
||||
if stops {
|
||||
let stop = main_mod.get::<StopFuncProto>("stop")?;
|
||||
// SAFETY: `conduwuit_router` exports `#[unsafe(no_mangle)] pub extern
|
||||
// "Rust" fn stop` with signature matching `StopFuncProto`, compiled
|
||||
// with the same toolchain and flags.
|
||||
let stop = unsafe { main_mod.get::<StopFuncProto>("stop")? };
|
||||
if let Err(error) = stop(
|
||||
server
|
||||
.services
|
||||
@@ -102,7 +111,9 @@ pub(crate) async fn open(server: &Arc<Server>) -> Result<usize, Error> {
|
||||
|
||||
for (i, name) in MODULE_NAMES.iter().enumerate() {
|
||||
if mods.get(i).is_none() {
|
||||
mods.push(mods::Module::from_name(name)?);
|
||||
// SAFETY: `MODULE_NAMES` are this workspace's own hot-reloadable
|
||||
// shared libraries built with the same compiler/ABI.
|
||||
mods.push(unsafe { mods::Module::from_name(name)? });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ pub(crate) async fn handle(
|
||||
.server
|
||||
.metrics
|
||||
.requests_handle_active
|
||||
.load(Ordering::Relaxed),
|
||||
.fetch_add(1, Ordering::Relaxed),
|
||||
handled = %services
|
||||
.server
|
||||
.metrics
|
||||
@@ -81,11 +81,7 @@ async fn execute(
|
||||
next: axum::middleware::Next,
|
||||
parent: &Span,
|
||||
) -> Response {
|
||||
services
|
||||
.server
|
||||
.metrics
|
||||
.requests_handle_active
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
#[cfg(debug_assertions)]
|
||||
conduwuit::defer! {{
|
||||
_ = services.server
|
||||
.metrics
|
||||
|
||||
@@ -8,7 +8,11 @@ use ruma::api::error::ErrorKind;
|
||||
|
||||
pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
|
||||
let router = Router::<state::State>::new();
|
||||
let (state, guard) = state::create(services.clone());
|
||||
// SAFETY: `guard` is returned alongside `router` and held in `serve()`
|
||||
// until the HTTP server has finished serving all requests and dropped
|
||||
// `router`, ensuring no `State` copy can be dereferenced after `Services`
|
||||
// is dropped.
|
||||
let (state, guard) = unsafe { state::create(services.clone()) };
|
||||
let router = conduwuit_api::router::build(router, state)
|
||||
.merge(conduwuit_web::build(services))
|
||||
.fallback(not_found)
|
||||
|
||||
@@ -112,27 +112,14 @@ 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(len.try_into().unwrap_or(u64::MAX), &[self.origin(mxc)]);
|
||||
}
|
||||
.record(file.len().try_into().unwrap_or(u64::MAX), &[self.origin(mxc)]);
|
||||
|
||||
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)]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn origin(&self, mxc: &Mxc<'_>) -> KeyValue {
|
||||
@@ -209,7 +196,12 @@ impl Service {
|
||||
.read_to_end(&mut content)
|
||||
.await?;
|
||||
|
||||
self.record_read(mxc, content.len());
|
||||
self.services
|
||||
.server
|
||||
.metrics
|
||||
.instruments
|
||||
.media_read_size
|
||||
.record(content.len().try_into().unwrap_or(u64::MAX), &[self.origin(mxc)]);
|
||||
|
||||
Ok(Some(FileMeta {
|
||||
content: Some(content),
|
||||
|
||||
@@ -44,7 +44,6 @@ 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(())
|
||||
}
|
||||
@@ -67,19 +66,13 @@ impl super::Service {
|
||||
// 0, 0 because that's the original file
|
||||
let dim = dim.normalized();
|
||||
|
||||
let thumbnail = match self.db.search_file_metadata(mxc, &dim).await {
|
||||
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
|
||||
@@ -139,7 +132,6 @@ 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, net::IpAddr, str::FromStr, sync::Arc, time::Duration};
|
||||
use std::{collections::HashMap, str::FromStr, sync::Arc, time::Duration};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
@@ -359,7 +359,6 @@ 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.");
|
||||
@@ -420,7 +419,7 @@ impl Service {
|
||||
// Create a new shadow user
|
||||
self.services
|
||||
.users
|
||||
.create_local_account(&user_id, None, None, Some(client_ip), None)
|
||||
.create_local_account(&user_id, None, None, None, None)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
error!("Failed to create a shadow user for {user_id}: {err}");
|
||||
|
||||
@@ -11,7 +11,15 @@ pub struct Guard {
|
||||
services: Arc<Services>,
|
||||
}
|
||||
|
||||
pub fn create(services: Arc<Services>) -> (State, Guard) {
|
||||
/// Create a raw-pointer `State` handle paired with a `Guard` that keeps
|
||||
/// `Services` alive.
|
||||
///
|
||||
/// # Safety
|
||||
/// `State` is `Copy` and dereferences its raw pointer without reference
|
||||
/// counting. The caller must ensure that no `State` (nor any copy of it) is
|
||||
/// dereferenced after `Guard` and all other `Arc<Services>` clones have been
|
||||
/// dropped.
|
||||
pub unsafe fn create(services: Arc<Services>) -> (State, Guard) {
|
||||
let state = State {
|
||||
services: Arc::into_raw(services.clone()),
|
||||
};
|
||||
|
||||
@@ -6,7 +6,6 @@ use axum::{
|
||||
response::Redirect,
|
||||
routing::on,
|
||||
};
|
||||
use conduwuit_api::client_ip::ClientIp;
|
||||
use conduwuit_service::{
|
||||
oauth::grant::AuthorizationCodeResponse,
|
||||
oidc::{ClaimedLocalUser, SessionCompletionStatus},
|
||||
@@ -64,7 +63,6 @@ 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);
|
||||
@@ -106,10 +104,7 @@ async fn route_complete(
|
||||
.await
|
||||
.expect("should be able to serialize oidc session");
|
||||
|
||||
services
|
||||
.oidc
|
||||
.complete_session(&claims, None, &client_ip)
|
||||
.await
|
||||
services.oidc.complete_session(&claims, None).await
|
||||
},
|
||||
| OidcSessionState::Authorized { claims } => {
|
||||
let supplied_user_id = if let Some(form) = form {
|
||||
@@ -168,7 +163,7 @@ async fn route_complete(
|
||||
|
||||
services
|
||||
.oidc
|
||||
.complete_session(&claims, supplied_user_id, &client_ip)
|
||||
.complete_session(&claims, supplied_user_id)
|
||||
.await
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user