Skip to content

Commit

Permalink
send heartbeats to heartbeat handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfl0wer committed Oct 20, 2024
1 parent d80cd80 commit a919632
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
31 changes: 25 additions & 6 deletions src/gateway/gateway_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,32 @@ pub(super) async fn gateway_task(
log::trace!(target: "symfonia::gateway::gateway_task", "Received raw message {:?}", message_of_unknown_type);
let event = unwrap_event(Event::try_from(message_of_unknown_type), connection.clone(), connection.kill_send.clone());
log::trace!(target: "symfonia::gateway::gateway_task", "Event type of received message: {:?}", event);
if event.op_code() == Opcode::Dispatch {
// Receiving a dispatch event from a client is never correct
log::debug!(target: "symfonia::gateway::gateway_task", "Received an unexpected message: {:?}", event);
connection.sender.send(Message::Close(Some(CloseFrame { code: tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode::Library(4002), reason: "DECODE_ERROR".into() })));
connection.kill_send.send(()).expect("Failed to send kill_send");
panic!("Killing gateway task: Received an unexpected message");
match event {
Event::Dispatch(_) => {
// Receiving a dispatch event from a client is never correct
log::debug!(target: "symfonia::gateway::gateway_task", "Received an unexpected message: {:?}", event);
connection.sender.send(Message::Close(Some(CloseFrame { code: tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode::Library(4002), reason: "DECODE_ERROR".into() })));
connection.kill_send.send(()).expect("Failed to send kill_send");
panic!("Killing gateway task: Received an unexpected message");
},
Event::Heartbeat(hearbeat_event) => {
match heartbeat_send.send(hearbeat_event) {
Err(e) => {
log::debug!(target: "symfonia::gateway::gateway_task", "Received Heartbeat but HeartbeatHandler seems to be dead?");
connection.sender.send(Message::Close(Some(CloseFrame { code: tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode::Library(4002), reason: "DECODE_ERROR".into() })));
connection.kill_send.send(()).expect("Failed to send kill_send");
panic!("Killing gateway task: Received an unexpected message");
},
Ok(_) => {
log::trace!(target: "symfonia::gateway::gateway_task", "Forwarded heartbeat message to HeartbeatHandler!");
}
}
}
_ => {
log::error!(target: "symfonia::gateway::gateway_task", "Received an event type for which no code is yet implemented in the gateway_task. Please open a issue or PR at the symfonia repository. {:?}", event);
}
}

},
Err(error) => {
connection.sender.send(Message::Close(Some(CloseFrame { code: tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode::Library(4000), reason: "INTERNAL_SERVER_ERROR".into() })));
Expand Down
1 change: 0 additions & 1 deletion src/gateway/heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ impl HeartbeatHandler {
}
};
self.connection.kill_send.send(()).expect("Failed to send kill signal in heartbeat_handler");
return;
}
}
}
Expand Down

0 comments on commit a919632

Please sign in to comment.