Skip to content

Commit 924c183

Browse files
committed
Reset state to DISCONNECTED after disconnect failure
1 parent a11c50a commit 924c183

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

android/app/src/main/java/betaflight/configurator/plugin/SocketPlugin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,16 @@ public void disconnect(final PluginCall call) {
181181
Log.d(TAG, "Disconnected successfully");
182182
} catch (Exception e) {
183183
state.set(ConnectionState.ERROR);
184+
// Ensure cleanup completes even on error
185+
try {
186+
closeResourcesInternal();
187+
} catch (Exception ce) {
188+
Log.e(TAG, "Cleanup error during disconnect", ce);
189+
}
184190
call.reject("Disconnect failed: " + e.getMessage());
185191
Log.e(TAG, "Disconnect failed", e);
192+
// Reset to a clean disconnected state after handling error
193+
state.set(ConnectionState.DISCONNECTED);
186194
} finally {
187195
socketLock.unlock();
188196
call.setKeepAlive(false);

0 commit comments

Comments
 (0)