(fix): fix connection issues

This commit is contained in:
Alois 2026-07-28 01:02:05 +02:00
commit 02bd4c0132
Signed by: alois
SSH key fingerprint: SHA256:GBzT2DXvAuGV9XIV5W3WrzVpjU54FThmxHXdbz95J24
2 changed files with 11 additions and 5 deletions

View file

@ -245,16 +245,20 @@ impl OmikronConnection {
}
pub async fn close(self: Arc<Self>) {
log_in!(
self.get_omikron_id().await.unwrap_or(0),
self.id as i64,
PrintType::Omega,
"Omikron connection Closed"
);
if let Some(sender) = self.sender.lock().await.take() {
sender.close();
}
}
async fn cleanup(self: Arc<Self>) {
if self.id != 0 {
log_in!(self.id as i64, PrintType::Omega, "Omikron disconnected");
omikron_manager::remove_omikron(self.id as i64).await;
crate::sql::user_online_tracker::untrack_omikron(self.id as i64).await;
if omikron_manager::remove_omikron(self.id as i64, &self).await {
crate::sql::user_online_tracker::untrack_omikron(self.id as i64).await;
}
}
if let Some(handle) = self.cleanup_handle.lock().unwrap().take() {
handle.abort();

View file

@ -22,8 +22,10 @@ pub async fn add_omikron(conn: Arc<OmikronConnection>) {
}
}
pub async fn remove_omikron(omikron_id: i64) {
OMIKRON_CONNECTIONS.remove(&omikron_id);
pub async fn remove_omikron(omikron_id: i64, connection: &Arc<OmikronConnection>) -> bool {
OMIKRON_CONNECTIONS
.remove_if(&omikron_id, |_, current| Arc::ptr_eq(current, connection))
.is_some()
}
pub fn get_connected_omikron(omikron_id: i64) -> Option<Arc<OmikronConnection>> {