Compare commits

...
5 Commits
Author SHA1 Message Date
IAmTomahawkx 8153f5f17a Don't panic on empty message list
... even though it shouldn't be possible.
2025-05-15 03:20:32 -07:00
izzy 99a80f723d chore: increase verbosity for ack logging 2025-05-14 11:46:56 +01:00
izzy 4f13f5899b fix: authifier should not use transactions for migrations 2025-05-14 11:40:07 +01:00
izzy 5362e84730 fix: don't try to mount env logger twice 2025-05-13 11:16:28 +01:00
izzy be89e62d54 fix: include pushd key in Revolt.toml 2025-05-13 11:04:43 +01:00
9 changed files with 45 additions and 33 deletions
Generated
+5 -4
View File
@@ -446,9 +446,9 @@ dependencies = [
[[package]]
name = "authifier"
version = "1.0.13"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca26cb6b5ab776a1de5a8122fe6cc77fadd84fed30704c496f2aca451637877b"
checksum = "b1a03b810b342b4c584cdc1cfc40d1ec763b1d653ef4086f7494740f35d9e1f0"
dependencies = [
"async-std",
"async-trait",
@@ -6478,9 +6478,9 @@ dependencies = [
[[package]]
name = "rocket_authifier"
version = "1.0.13"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0490f4a6f0a359a9ffff9acbdf4eddf49890ec94941b8ddd88163c16f6159f5a"
checksum = "c1f98a5be96ac4144ee1adc809c1594e8212032b8a08d9bc4cef70735dfd976e"
dependencies = [
"authifier",
"iso8601-timestamp",
@@ -8294,6 +8294,7 @@ checksum = "220b18413e1fe5e85a5580b22f44241f82404a66c792c9f3c9eda74c52d9a22e"
dependencies = [
"chrono",
"rand 0.8.5",
"serde",
]
[[package]]
+1 -1
View File
@@ -36,7 +36,7 @@ async-std = { version = "1.8.0", features = [
] }
# core
authifier = { version = "1.0.13" }
authifier = { version = "1.0.15" }
revolt-result = { path = "../core/result" }
revolt-models = { path = "../core/models" }
revolt-config = { path = "../core/config" }
+1
View File
@@ -275,4 +275,5 @@ api = ""
events = ""
files = ""
proxy = ""
pushd = ""
crond = ""
+1 -1
View File
@@ -97,7 +97,7 @@ web-push = "0.10.0"
revolt_a2 = { version = "0.10", default-features = false, features = ["ring"] }
# Authifier
authifier = { version = "1.0.13", features = ["rocket_impl"] }
authifier = { version = "1.0.15", features = ["rocket_impl"] }
# RabbitMQ
amqprs = { version = "1.7.0" }
@@ -21,7 +21,7 @@ struct MigrationInfo {
revision: i32,
}
pub const LATEST_REVISION: i32 = 32;
pub const LATEST_REVISION: i32 = 33; // MUST BE +1 to last migration
pub async fn migrate_database(db: &MongoDb) {
let migrations = db.col::<Document>("migrations");
+31 -20
View File
@@ -3,6 +3,7 @@ use crate::{Database, Message, AMQP};
use deadqueue::limited::Queue;
use once_cell::sync::Lazy;
use revolt_config::capture_message;
use revolt_models::v0::PushNotification;
use std::{
collections::{HashMap, HashSet},
@@ -64,6 +65,7 @@ pub async fn queue_ack(channel: String, user: String, event: AckEvent) {
);
}
/// Do not add more than one message per event.
pub async fn queue_message(channel: String, event: AckEvent) {
Q.try_push(Data {
channel,
@@ -113,7 +115,7 @@ pub async fn handle_ack_event(
}
AckEvent::ProcessMessage { messages } => {
let mut users: HashSet<&String> = HashSet::new();
debug!(
info!(
"Processing {} messages from channel {}",
messages.len(),
messages[0].1.channel
@@ -124,7 +126,7 @@ pub async fn handle_ack_event(
users.extend(recipents.iter());
});
debug!("Found {} users to notify.", users.len());
info!("Found {} users to notify.", users.len());
for user in users {
let message_ids: Vec<String> = messages
@@ -142,7 +144,7 @@ pub async fn handle_ack_event(
db.add_mention_to_unread(channel, user, &message_ids)
.await?;
}
debug!("Added {} mentions for user {}", message_ids.len(), &user);
info!("Added {} mentions for user {}", message_ids.len(), &user);
}
let mut mass_mentions = vec![];
@@ -231,7 +233,7 @@ pub async fn worker(db: Database, amqp: AMQP) {
revolt_config::capture_error(&err);
error!("{err:?} for {event:?}. ({user:?}, {channel})");
} else {
debug!("User {user:?} ack in {channel} with {event:?}");
info!("User {user:?} ack in {channel} with {event:?}");
}
}
}
@@ -246,6 +248,8 @@ pub async fn worker(db: Database, amqp: AMQP) {
mut event,
}) = Q.try_pop()
{
info!("Took next ack from queue, now {} remaining", Q.len());
let key: (Option<String>, String, u8) = (
user,
channel,
@@ -260,24 +264,31 @@ pub async fn worker(db: Database, amqp: AMQP) {
if let AckEvent::ProcessMessage { messages: existing } =
&mut task.data.event
{
// add the new message to the list of messages to be processed.
existing.append(new_data);
if let Some(new_event) = new_data.pop() {
// if the message contains a mass mention, do not delay it any further.
if new_event.1.contains_mass_push_mention() {
// add the new message to the list of messages to be processed.
existing.push(new_event);
task.run_immediately();
continue;
}
// if the message contains a mass mention, do not delay it any further.
if new_data[0].1.contains_mass_push_mention() {
task.run_immediately();
continue;
}
existing.push(new_event);
// put a cap on the amount of messages that can be queued, for particularly active channels
if (existing.length() as u16)
< revolt_config::config()
.await
.features
.advanced
.process_message_delay_limit
{
task.delay();
// put a cap on the amount of messages that can be queued, for particularly active channels
if (existing.length() as u16)
< revolt_config::config()
.await
.features
.advanced
.process_message_delay_limit
{
task.delay();
}
} else {
let err_msg = format!("Got zero-length message event: {event:?}");
capture_message(&err_msg, revolt_config::Level::Warning);
info!("{err_msg}")
}
} else {
panic!("Somehow got an ack message in the add mention arm");
+1 -1
View File
@@ -28,7 +28,7 @@ tokio = "1.39.2"
async-trait = "0.1.81"
ulid = "1.0.0"
authifier = "1.0.10"
authifier = "1.0.15"
log = "0.4.11"
pretty_env_logger = "0.4.0"
+2 -3
View File
@@ -24,9 +24,6 @@ use consumers::{
#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
async fn main() {
let config = config().await;
pretty_env_logger::init();
// Configure logging and environment
revolt_config::configure!(pushd);
@@ -55,6 +52,8 @@ async fn main() {
// This'll require some interesting shimming if we need to add more events once this is in prod (different payloads between prod and test),
// but that sounds like a problem for future us.
let config = config().await;
// inbound: generic
connections.push(
make_queue_and_consume(
+2 -2
View File
@@ -56,7 +56,7 @@ lettre = "0.10.0-alpha.4"
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", rev = "072d90359b23e9b291df6b672c07c93de9c46011" }
rocket_empty = { version = "0.1.1", features = ["schema"] }
rocket_authifier = { version = "1.0.13" }
rocket_authifier = { version = "1.0.15" }
rocket_prometheus = "0.10.0-rc.3"
# spec generation
@@ -67,7 +67,7 @@ revolt_rocket_okapi = { version = "0.10.0", features = ["swagger"] }
amqprs = { version = "1.7.0" }
# core
authifier = "1.0.13"
authifier = "1.0.15"
revolt-config = { path = "../core/config" }
revolt-database = { path = "../core/database", features = [
"rocket-impl",