mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-28 06:24:10 +01:00
OP-825 Fix null reference and race condition when shutting down service
This commit is contained in:
parent
1d96dfd30e
commit
2f046187ca
@ -241,7 +241,13 @@ public class OPTelemetryService extends Service {
|
||||
telemTask = null;
|
||||
|
||||
try {
|
||||
activeTelem.join();
|
||||
// Race condition - if we shut the service down before the telemetry task
|
||||
// thread has started, this will hang so we need to check thread is runnable.
|
||||
if(activeTelem.getState() == Thread.State.RUNNABLE){
|
||||
activeTelem.join();
|
||||
}else{
|
||||
Log.d(TAG, "onDestroy() shut down telemetry task before it has started");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -142,12 +142,16 @@ public abstract class TelemetryTask implements Runnable {
|
||||
}
|
||||
|
||||
// Stop the master telemetry thread
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Looper.myLooper().quit();
|
||||
}
|
||||
});
|
||||
// Check handler is not null: if we attempt to disconnect before
|
||||
// the connect process has completed, handler may be null.
|
||||
if(handler != null){
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Looper.myLooper().quit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (inputProcessThread != null) {
|
||||
inputProcessThread.interrupt();
|
||||
|
Loading…
Reference in New Issue
Block a user