Skip to content

Commit

Permalink
VSR: Fix liveness issue for misdirected reply messages
Browse files Browse the repository at this point in the history
We now also ignore unexpected commands in the Replica's
on_message() handler as we were doing for the Client,
and we use an exhaustive switch, which would also have
been better in the first place.

Reported-by: @ThreeFx
Refs: #9
  • Loading branch information
jorangreef committed Sep 15, 2021
1 parent 119c889 commit 146a3d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/vsr/client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ pub fn Client(comptime StateMachine: type, comptime MessageBus: type) type {
.reply => self.on_reply(message),
.eviction => self.on_eviction(message),
else => {
// This could be because of a misdirected packet.
log.warn(
"{}: on_message: unexpected command {}",
.{ self.id, message.header.command },
);
log.warn("{}: on_message: ignoring misdirected {s} message", .{
self.id,
@tagName(message.header.command),
});
return;
},
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/vsr/replica.zig
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ pub fn Replica(
return;
}

// No client or replica should ever send a .reserved message.
assert(message.header.command != .reserved);

if (message.header.cluster != self.cluster) {
log.warn("{}: on_message: wrong cluster (cluster must be {} not {})", .{
self.replica,
Expand Down Expand Up @@ -485,12 +488,21 @@ pub fn Replica(
.do_view_change => self.on_do_view_change(message),
.start_view => self.on_start_view(message),
.recovery => self.on_recovery(message),
.recovery_response => return, // TODO
.request_start_view => self.on_request_start_view(message),
.request_prepare => self.on_request_prepare(message),
.request_headers => self.on_request_headers(message),
.headers => self.on_headers(message),
.nack_prepare => self.on_nack_prepare(message),
else => unreachable,
// A replica should never handle misdirected messages intended for a client:
.eviction, .reply => {
log.warn("{}: on_message: ignoring misdirected {s} message", .{
self.replica,
@tagName(message.header.command),
});
return;
},
.reserved => unreachable,
}

if (self.loopback_queue) |loopback_message| {
Expand Down

0 comments on commit 146a3d7

Please sign in to comment.