Skip to content

Commit

Permalink
Fail resumption if it happens in different thread (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
somasun authored and lehecka committed Aug 9, 2017
1 parent 13b4ba9 commit 0c81960
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rsocket/RSocketServer.cpp
Expand Up @@ -160,6 +160,9 @@ void RSocketServer::onRSocketResume(
}
auto serverState = std::move(result.value());
CHECK(serverState);
if (!serverState->rSocketStateMachine_->isInEventBaseThread()) {
throw RSocketException("Trying to RESUME in a different worker thread");
}
serverState->rSocketStateMachine_->resumeServer(
std::move(frameTransport), resumeParams);
}
Expand Down
1 change: 1 addition & 0 deletions rsocket/internal/SetupResumeAcceptor.cpp
Expand Up @@ -170,6 +170,7 @@ void SetupResumeAcceptor::processFrame(
} catch (const std::exception& exn) {
folly::exception_wrapper ew{std::current_exception(), exn};
auto errFrame = Frame_ERROR::rejectedResume(ew.what().toStdString());
VLOG(3) << "Out: " << errFrame;
transport->outputFrameOrEnqueue(
serializer->serializeOut(std::move(errFrame)));
close(std::move(transport), std::move(ew));
Expand Down
4 changes: 4 additions & 0 deletions rsocket/statemachine/RSocketStateMachine.cpp
Expand Up @@ -880,6 +880,10 @@ void RSocketStateMachine::connectClientSendSetup(
connect(std::move(frameTransport), true, ProtocolVersion::Unknown);
}

bool RSocketStateMachine::isInEventBaseThread() {
return dynamic_cast<folly::EventBase*>(&executor_)->isInEventBaseThread();
}

void RSocketStateMachine::writeNewStream(
StreamId streamId,
StreamType streamType,
Expand Down
2 changes: 2 additions & 0 deletions rsocket/statemachine/RSocketStateMachine.h
Expand Up @@ -211,6 +211,8 @@ class RSocketStateMachine final
return connectionEvents_;
}

bool isInEventBaseThread();

private:

bool connect(
Expand Down

0 comments on commit 0c81960

Please sign in to comment.