@@ -68,6 +68,7 @@ bool BedrockCore::isTimedOut(unique_ptr<BedrockCommand>& command) {
68
68
BedrockCore::RESULT BedrockCore::peekCommand (unique_ptr<BedrockCommand>& command, bool exclusive) {
69
69
AutoTimer timer (command, BedrockCommand::PEEK);
70
70
BedrockServer::ScopedStateSnapshot snapshot (_server);
71
+ command->lastPeekedOrProcessedInState = _server.getState ();
71
72
72
73
// Convenience references to commonly used properties.
73
74
const SData& request = command->request ;
@@ -176,6 +177,15 @@ BedrockCore::RESULT BedrockCore::processCommand(unique_ptr<BedrockCommand>& comm
176
177
AutoTimer timer (command, BedrockCommand::PROCESS);
177
178
BedrockServer::ScopedStateSnapshot snapshot (_server);
178
179
180
+ // We need to be leading (including standing down) and we need to have peeked this command in the same set of
181
+ // states, or we can't complete this command (we can't commit the command of we're not leading, and if we're
182
+ // leading but were following when we peeked, we may try to read HTTPS requests we never made).
183
+ if ((command->lastPeekedOrProcessedInState != SQLiteNode::LEADING && command->lastPeekedOrProcessedInState != SQLiteNode::STANDINGDOWN) ||
184
+ (_server.getState () != SQLiteNode::LEADING && _server.getState () != SQLiteNode::STANDINGDOWN)) {
185
+ return RESULT::SERVER_NOT_LEADING;
186
+ }
187
+ command->lastPeekedOrProcessedInState = _server.getState ();
188
+
179
189
// Convenience references to commonly used properties.
180
190
const SData& request = command->request ;
181
191
SData& response = command->response ;
0 commit comments