Skip to content

Commit

Permalink
Merge pull request #93 from 4t145/fix-ws-quit-task-after-error
Browse files Browse the repository at this point in the history
fix websocket quit the process task after error
  • Loading branch information
4t145 authored Dec 6, 2023
2 parents eeba49e + 9f7afdf commit 3de755f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions tardis/src/cluster/cluster_hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use std::{
time::{Duration, Instant},
};

use crate::basic::{json::TardisJson, result::TardisResult};
use crate::{
basic::{json::TardisJson, result::TardisResult},
TardisFuns,
};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::hash::Hash;
Expand Down Expand Up @@ -101,7 +104,7 @@ where
}
}
pub fn is_cluster(&self) -> bool {
self.cluster_sync
self.cluster_sync && TardisFuns::fw_config().cluster.is_some()
}
pub fn event_name(&self) -> String {
format!("tardis/hashmap/{ident}", ident = self.ident)
Expand Down
2 changes: 1 addition & 1 deletion tardis/src/web/ws_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl TardisWSClient {
}
}

async fn reconnect(&self) -> TardisResult<()> {
pub async fn reconnect(&self) -> TardisResult<()> {
if let Ok(permit) = self.connection_semaphore.clone().try_acquire_owned() {
info!("[Tardis.WSClient] trying to reconnect {url}", url = self.url);
let sender = Self::do_connect(&self.url, self.on_message.clone(), true, permit).await?;
Expand Down
10 changes: 5 additions & 5 deletions tardis/src/web/ws_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ where
match TardisFuns::json.str_to_obj::<TardisWebsocketReq>(&text) {
Err(_) => {
ws_send_error_to_channel(&text, "message illegal", &avatar_self, &inst_id, &inner_sender);
break;
continue;
}
Ok(req_msg) => {
// Security check
if !mgr_node && req_msg.spec_inst_id.is_some() {
ws_send_error_to_channel(&text, "spec_inst_id can only be specified on the management node", &avatar_self, &inst_id, &inner_sender);
break;
continue;
}
if !mgr_node && !current_avatars.contains(&req_msg.from_avatar) {
ws_send_error_to_channel(&text, "from_avatar is not illegal", &avatar_self, &inst_id, &inner_sender);
break;
ws_send_error_to_channel(&text, "from_avatar is illegal", &avatar_self, &inst_id, &inner_sender);
continue;
}
// System process
if req_msg.event == Some(WS_SYSTEM_EVENT_INFO.to_string()) {
Expand All @@ -215,7 +215,7 @@ where
ws_send_error_to_channel(&text, "message illegal", &avatar_self, &inst_id, &inner_sender);
})
else {
break;
continue;
};
let send_msg = TardisWebsocketMgrMessage {
id: TardisFuns::field.nanoid(),
Expand Down

0 comments on commit 3de755f

Please sign in to comment.