Issue Description
Some developers have reported that their Android app crashes silently (without any visible error) when calling the RtmClient.release() method during cleanup — usually right after ending a call or logging out from Agora RTM.
The crash typically occurs inconsistently and may not be reproducible every time.
Platform/SDK
Platform: Android
SDK: Agora RTM SDK v2.2.4
Product: Video Calling (Signaling)
Error Message
The crash log may look like the following:
Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xffff00000018
in tid 17942 (DefaultDispatch), pid 17340 (com.simpleviralgames.hopmate.debug)
Cmdline: pid: 11729, tid: 11763, name: DefaultDispatch
#00 pc 000000000040d648 /data/app/.../libagora-rtm-sdk.so
Step-by-Step Solution
Step 1: Ensure All RTM Operations Are Completed Before Release
Before calling RtmClient.release(), make sure that no asynchronous operations are still in progress, such as:
Presence or attribute updates
Logout requests
Any pending callbacks
👉 Always wait for completion callbacks:
// Logout example
rtmClient.logout(new ResultCallback<Void>() {
@Override
public void onSuccess(Void response) {
// Wait for logout success before releasing
new Handler(Looper.getMainLooper()).postDelayed(() -> {
rtmClient.release();
}, 300); // small delay (300ms)
}
@Override
public void onFailure(ErrorInfo errorInfo) {
Log.e("Agora", "Logout failed: " + errorInfo);
}
});
Step 2: Maintain the Correct Operation Order
Follow this sequence to ensure safe cleanup:
Complete all presence or attribute operations.
Call
logout().Wait for
onLogout()success callback.Add a short delay (200–500ms).
Then call
release().
Step 3: Avoid Accessing Released Client Instances
Ensure no background tasks, listeners, or callbacks attempt to use the RTM client after release.
Null-check all references before reuse.
Clear event handlers/listeners before calling
release().
Step 4: Optional – Add a Defensive Try-Catch
In debug builds, you may wrap the cleanup logic in a try-catch to log unexpected behavior:
try {
rtmClient.release();
} catch (Exception e) {
Log.e("Agora", "Safe release failed: ", e);
}
Root Cause
The crash occurs when RtmClient.release() is called while the SDK’s internal threads are still processing callbacks or background operations (e.g., presence update, logout event).
This causes a segmentation fault inside the native libagora-rtm-sdk.so library because underlying resources are freed prematurely.
Prevention / Best Practices
Always wait for asynchronous callbacks (like
onLogout()) before releasing.Add a short grace delay (200–500ms) after logout to ensure background threads terminate cleanly.
Avoid calling
release()from within callback threads that may still be using the SDK.Implement state flags to prevent duplicate release calls.
Corresponding Document / Link