Skip to content

Commit

Permalink
Merge pull request #1826 from Expensify/dan/prevent-double-detach-crash
Browse files Browse the repository at this point in the history
Do not crash if the detach command is sent twice.
  • Loading branch information
tylerkaraszewski authored Jul 31, 2024
2 parents d024841 + 099d75d commit a70564a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
8 changes: 6 additions & 2 deletions BedrockServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,8 +1798,12 @@ void BedrockServer::_control(unique_ptr<BedrockCommand>& command) {
} else if (SIEquals(command->request.methodLine, "ConflictReport")) {
response.content = _conflictManager.generateReport();
} else if (SIEquals(command->request.methodLine, "Detach")) {
response.methodLine = "203 DETACHING";
_beginShutdown("Detach", true);
if (isDetached()) {
response.methodLine = "400 Already detached";
} else {
response.methodLine = "203 DETACHING";
_beginShutdown("Detach", true);
}
} else if (SIEquals(command->request.methodLine, "Attach")) {
// Ensure none of our plugins are blocking attaching
list<string> blockingPlugins;
Expand Down
38 changes: 38 additions & 0 deletions test/clustertest/tests/DoubleDetachTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>

#include <libstuff/SData.h>
#include <test/clustertest/BedrockClusterTester.h>

struct DoubleDetachTest : tpunit::TestFixture {
DoubleDetachTest()
: tpunit::TestFixture("DoubleDetach",
BEFORE_CLASS(DoubleDetachTest::setup),
AFTER_CLASS(DoubleDetachTest::teardown),
TEST(DoubleDetachTest::testDoubleDetach)) { }

BedrockClusterTester* tester;

void setup() {
tester = new BedrockClusterTester();
}

void teardown() {
delete tester;
}

void testDoubleDetach()
{
// Test a control command
BedrockTester& follower = tester->getTester(1);

// Detach
SData detachCommand("detach");
follower.executeWaitVerifyContent(detachCommand, "203 DETACHING", true);

// Wait for it to detach
sleep(3);

follower.executeWaitVerifyContent(detachCommand, "400 Already detached", true);
}

} __DoubleDetachTest;

0 comments on commit a70564a

Please sign in to comment.