Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): improve logging for deserializing invalid server command #1548

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion server/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bytes::{BufMut, Bytes, BytesMut};
use error_set::ErrContext;
use iggy::command::*;
use iggy::consumer_groups::create_consumer_group::CreateConsumerGroup;
use iggy::consumer_groups::delete_consumer_group::DeleteConsumerGroup;
Expand Down Expand Up @@ -51,6 +52,7 @@ use iggy::{
};
use std::fmt::{Display, Formatter};
use strum::EnumString;
use tracing::error;

#[derive(Debug, PartialEq, EnumString)]
pub enum ServerCommand {
Expand Down Expand Up @@ -156,6 +158,7 @@ impl BytesSerializable for ServerCommand {
let code = u32::from_le_bytes(
bytes[..4]
.try_into()
.with_error_context(|e| format!("failed to decode command from bytes, error: {e}"))
.map_err(|_| IggyError::InvalidNumberEncoding)?,
);
let payload = bytes.slice(4..);
Expand Down Expand Up @@ -263,7 +266,10 @@ impl BytesSerializable for ServerCommand {
GET_SNAPSHOT_FILE_CODE => Ok(ServerCommand::GetSnapshotFile(GetSnapshot::from_bytes(
payload,
)?)),
_ => Err(IggyError::InvalidCommand),
_ => {
error!("Invalid server command: {code}");
Err(IggyError::InvalidCommand)
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion server/src/tcp/connection_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub(crate) async fn handle_connection(
sender.read(&mut command_buffer).await?;
let command = ServerCommand::from_bytes(command_buffer.freeze());
if command.is_err() {
error!("Received an invalid TCP command.");
sender
.send_error_response(IggyError::InvalidCommand)
.await?;
Expand Down