diff --git a/backend/src/agent/agent.rs b/backend/src/agent/agent.rs index 70672cf..7abcdee 100644 --- a/backend/src/agent/agent.rs +++ b/backend/src/agent/agent.rs @@ -65,7 +65,7 @@ impl Actor for Agent { impl Handler for Agent { type Result = (); - fn handle(&mut self, msg: AgentMsg, _ctx: &mut Context) -> Self::Result { + fn handle(&mut self, msg: AgentMsg, ctx: &mut Context) -> Self::Result { match msg { AgentMsg::Ready(ws_addr) => { self.ws_addr = Some(ws_addr); @@ -89,7 +89,10 @@ impl Handler for Agent { .do_send(ws::WsMsg::SendToClient(data)); } } - _ => panic!("unexpected message"), + AgentMsg::Shutdown => { + info!("Agent {} - Shutdown", self.server_info); + ctx.stop(); + } } } } diff --git a/backend/src/agent/ws.rs b/backend/src/agent/ws.rs index b16cd18..f92e8cd 100644 --- a/backend/src/agent/ws.rs +++ b/backend/src/agent/ws.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use actix::ActorContext; use actix::{Actor, Addr, Message, StreamHandler}; use actix::{AsyncContext, Handler}; use actix_session::Session; @@ -53,6 +54,10 @@ impl StreamHandler> for WsSession { Ok(ws::Message::Binary(bin)) => { self.agent.do_send(AgentMsg::SendToServer(bin)); } + Ok(ws::Message::Close(_)) => { + self.agent.do_send(AgentMsg::Shutdown); + ctx.stop(); + } _ => (), } }