Skip to content

Commit 392a4b0

Browse files
authored
Added fix for hang on exit (#37)
1 parent cdec75f commit 392a4b0

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#pragma once
2020

21+
#include <atomic>
2122
#include <boost/asio.hpp>
2223
#include <aasdk/Transport/ITransport.hpp>
2324
#include <aasdk/Channel/Control/IControlServiceChannel.hpp>
@@ -86,6 +87,8 @@ class AndroidAutoEntity: public IAndroidAutoEntity, public aasdk::channel::contr
8687
ServiceList serviceList_;
8788
IPinger::Pointer pinger_;
8889
IAndroidAutoEntityEventHandler* eventHandler_;
90+
// Guard to avoid re-entrant quit handling and spurious error-triggered quits during shutdown
91+
std::atomic<bool> stopping_{false};
8992
};
9093

9194
}

src/autoapp/Service/AndroidAutoEntity.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ namespace f1x {
6161
}
6262

6363
void AndroidAutoEntity::stop() {
64+
// Mark stopping early to suppress error-triggered quits during teardown
65+
stopping_.store(true, std::memory_order_relaxed);
6466
strand_.dispatch([this, self = this->shared_from_this()]() {
6567
OPENAUTO_LOG(info) << "[AndroidAutoEntity] stop()";
6668

@@ -315,6 +317,10 @@ namespace f1x {
315317
}
316318

317319
void AndroidAutoEntity::onChannelError(const aasdk::error::Error &e) {
320+
if (stopping_.load(std::memory_order_relaxed)) {
321+
OPENAUTO_LOG(info) << "[AndroidAutoEntity] onChannelError() during stopping, ignoring: " << e.what();
322+
return;
323+
}
318324
OPENAUTO_LOG(fatal) << "[AndroidAutoEntity] onChannelError(): " << e.what();
319325
this->triggerQuit();
320326
}

src/autoapp/Service/Sensor/SensorService.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ namespace f1x::openauto::autoapp::service::sensor {
5757
this->stopPolling = true;
5858

5959
strand_.dispatch([this, self = this->shared_from_this()]() {
60+
// Cancel any pending timers to stop scheduling further polling callbacks immediately
61+
boost::system::error_code ec;
62+
this->timer_.cancel(ec);
63+
if (ec) {
64+
OPENAUTO_LOG(warning) << "[SensorService] timer cancel error: " << ec.message();
65+
}
6066
if (this->gpsEnabled_) {
6167
gps_stream(&this->gpsData_, WATCH_DISABLE, NULL);
6268
gps_close(&this->gpsData_);

0 commit comments

Comments
 (0)