fix: panic on launch

Now we start the admin and sending threads at a later time.
This commit is contained in:
Timo Kösters 2022-10-08 13:57:01 +02:00 committed by Nyaaori
parent 50b0eb9929
commit 8b5b7a1f63
No known key found for this signature in database
GPG key ID: E7819C3ED4D1F82E
20 changed files with 46 additions and 53 deletions

View file

@ -12,7 +12,7 @@ use std::{
use crate::{
api::{appservice_server, server_server},
services,
utils::{calculate_hash},
utils::calculate_hash,
Config, Error, PduEvent, Result,
};
use federation::transactions::send_transaction_message;
@ -37,7 +37,7 @@ use ruma::{
};
use tokio::{
select,
sync::{mpsc, Semaphore},
sync::{mpsc, Mutex, Semaphore},
};
use tracing::{error, warn};
@ -88,6 +88,7 @@ pub struct Service {
/// The state for a given state hash.
pub(super) maximum_requests: Arc<Semaphore>,
pub sender: mpsc::UnboundedSender<(OutgoingKind, SendingEventType, Vec<u8>)>,
receiver: Mutex<mpsc::UnboundedReceiver<(OutgoingKind, SendingEventType, Vec<u8>)>>,
}
enum TransactionStatus {
@ -99,25 +100,24 @@ enum TransactionStatus {
impl Service {
pub fn build(db: &'static dyn Data, config: &Config) -> Arc<Self> {
let (sender, receiver) = mpsc::unbounded_channel();
let self1 = Arc::new(Self {
Arc::new(Self {
db,
sender,
receiver: Mutex::new(receiver),
maximum_requests: Arc::new(Semaphore::new(config.max_concurrent_requests as usize)),
});
let self2 = Arc::clone(&self1);
tokio::spawn(async move {
self2.start_handler(receiver).await.unwrap();
});
self1
})
}
async fn start_handler(
&self,
mut receiver: mpsc::UnboundedReceiver<(OutgoingKind, SendingEventType, Vec<u8>)>,
) -> Result<()> {
pub fn start_handler(self: &Arc<Self>) {
let self2 = Arc::clone(&self);
tokio::spawn(async move {
self2.handler().await.unwrap();
});
}
async fn handler(&self) -> Result<()> {
let mut receiver = self.receiver.lock().await;
let mut futures = FuturesUnordered::new();
let mut current_transaction_status = HashMap::<OutgoingKind, TransactionStatus>::new();