Skip to content

Commit

Permalink
chore: Add logging for debugging disconnect handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nesium committed Jun 24, 2024
1 parent 0ddb177 commit 3baaa51
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions bindings/prose-sdk-js/src/connector/strophe_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use jid::FullJid;
use minidom::Element;
use secrecy::{ExposeSecret, Secret};
use thiserror::Error;
use tracing::warn;
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::spawn_local;
use web_sys::DomException;
Expand Down Expand Up @@ -158,6 +159,7 @@ impl ConnectionTrait for Connection {
impl EventHandler {
#[wasm_bindgen(js_name = "handleDisconnect")]
pub fn handle_disconnect(&self, error: Option<String>) {
warn!(">>> JS CALLED HANDLE DISCONNECT");
let fut = (self.handler)(
&self.connection,
ConnectionEvent::Disconnected {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use anyhow::Result;
use async_trait::async_trait;
use tracing::warn;

use prose_proc_macros::InjectDependencies;

Expand Down Expand Up @@ -47,8 +48,10 @@ impl ConnectionEventHandler {
// can be sure that we have everything we need.
}
ConnectionEvent::Disconnected { error } => {
warn!(">>> 1 EVENT HANDLER RECEIVED DISCONNECTED EVENT");
self.ctx.set_connection_state(ConnectionState::Disconnected);
self.sidebar_domain_service.handle_disconnect().await?;
warn!(">>> 2 EVENT HANDLER RECEIVED DISCONNECTED EVENT");
self.client_event_dispatcher
.dispatch_event(ClientEvent::ConnectionStatusChanged {
event: ClientConnectionEvent::Disconnect { error },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::time::Duration;

use futures::StreamExt;
use tokio::sync::mpsc::{channel, Sender};
use tracing::debug;
use tracing::{debug, warn};

use prose_wasm_utils::{spawn, ProseStreamExt, ReceiverStream};

Expand Down Expand Up @@ -88,19 +88,22 @@ impl ClientEventDispatcherTrait for CoalescingClientEventDispatcher {
event: ConnectionEvent::Disconnect { .. },
} = event
{
warn!(">>> 1 COALESCINGEVENTDISPATCHER RECEIVED DISCONNECTED EVENT");
let Some(delegate) = &self.delegate else {
warn!(">>> 2 COALESCINGEVENTDISPATCHER RECEIVED DISCONNECTED EVENT");
return;
};

warn!(">>> 3 COALESCINGEVENTDISPATCHER RECEIVED DISCONNECTED EVENT");
let Some(client_inner) = self
.client_inner
.get()
.expect("ClientInner was not set on ClientEventDispatcher")
.upgrade()
else {
warn!(">>> 4 COALESCINGEVENTDISPATCHER RECEIVED DISCONNECTED EVENT");
return;
};

warn!(">>> 5 COALESCINGEVENTDISPATCHER RECEIVED DISCONNECTED EVENT");
let client = Client::from(client_inner);
return delegate.handle_event(client, event);
};
Expand Down
3 changes: 3 additions & 0 deletions crates/prose-xmpp/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl ClientInner {
}

fn disconnect(&self) {
warn!(">>> DISCONNECT CALLED");
Self::cancel_pending_futures(&self.context);
self.context.disconnect()
}
Expand All @@ -129,7 +130,9 @@ impl ClientInner {
async fn handle_event(self: Arc<Self>, event: ConnectionEvent) {
match event {
ConnectionEvent::Disconnected { error } => {
warn!(">>> 1 XMPP CLIENT RECEIVED DISCONNECTED EVENT");
Self::cancel_pending_futures(&self.context);
warn!(">>> 2 XMPP CLIENT RECEIVED DISCONNECTED EVENT");
self.context
.clone()
.schedule_event(ClientEvent::Client(Event::Disconnected { error }))
Expand Down
24 changes: 22 additions & 2 deletions crates/prose-xmpp/src/client/module_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use anyhow::Result;
use jid::{BareJid, DomainPart, FullJid, NodePart, ResourcePart};
use minidom::Element;
use parking_lot::{Mutex, RwLock};
use tracing::instrument;
use tracing::{instrument, warn};
use uuid::Uuid;
use xmpp_parsers::iq::{Iq, IqType};
use xmpp_parsers::pubsub;
Expand Down Expand Up @@ -169,7 +169,27 @@ impl ModuleContextInner {

#[cfg(any(not(feature = "test"), target_arch = "wasm32"))]
pub(crate) fn schedule_event(self: Arc<Self>, event: Event) {
let fut = (self.event_handler)(self.clone().try_into().unwrap(), event);
let is_disconnect_event =
if let Event::Client(crate::client::Event::Disconnected { .. }) = &event {
true
} else {
false
};

if is_disconnect_event {
warn!(">>> 1 SCHEDULE DISCONNECTED EVENT");
}

let self_clone = self.clone();
let fut = Box::pin(async move {
if is_disconnect_event {
warn!(">>> 2 SCHEDULE DISCONNECTED EVENT");
}
(self.event_handler)(self_clone.try_into().unwrap(), event).await;
if is_disconnect_event {
warn!(">>> 3 SCHEDULE DISCONNECTED EVENT");
}
});
prose_wasm_utils::spawn(fut);
}

Expand Down

0 comments on commit 3baaa51

Please sign in to comment.