Skip to content

Commit

Permalink
Merge pull request #1584 from mavlink/pr-fix-timeout-crash
Browse files Browse the repository at this point in the history
mavsdk_server: fix crash on disconnect
  • Loading branch information
JonasVautherin authored Oct 28, 2021
2 parents 5c4b7fe + 828541c commit 00290d6
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/mavsdk_server/src/core/core_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ class CoreServiceImpl final : public mavsdk::rpc::core::CoreService::Service {
const rpc::core::SubscribeConnectionStateRequest* /* request */,
grpc::ServerWriter<rpc::core::ConnectionStateResponse>* writer) override
{
std::mutex connection_state_mutex{};

_mavsdk.subscribe_on_new_system([this, writer, &connection_state_mutex]() {
publish_system_state(writer, connection_state_mutex);
});
_mavsdk.subscribe_on_new_system(
[this, writer]() { publish_system_state(writer, _connection_state_mutex); });

// Publish the current state on subscribe
publish_system_state(writer, connection_state_mutex);
publish_system_state(writer, _connection_state_mutex);

_stop_future.wait();
return grpc::Status::OK;
Expand All @@ -51,8 +48,8 @@ class CoreServiceImpl final : public mavsdk::rpc::core::CoreService::Service {
private:
Mavsdk& _mavsdk;
std::promise<void> _stop_promise;

std::future<void> _stop_future;
std::mutex _connection_state_mutex{};

static mavsdk::rpc::core::ConnectionStateResponse
createRpcConnectionStateResponse(const bool is_connected)
Expand Down

0 comments on commit 00290d6

Please sign in to comment.