Skip to content

Async void onInit() Missing Error Handling in LiveKitController #613

@Eshaan-byte

Description

@Eshaan-byte

🐛 Describe the bug

The LiveKitController has a critical initialization bug that causes app crashes when LiveKit connection fails. The onInit() method is declared as async void, which prevents proper error propagation and leads to LateInitializationError crashes when network conditions are poor or LiveKit server is unreachable. Severity: HIGH - Causes app crashes in production Affected Users: Anyone joining audio rooms with unstable network
Sample Code to Reproduce
// Current problematic implementation in lib/controllers/livekit_controller.dart:33-42

class LiveKitController extends GetxController {
late final Room liveKitRoom; // ❌ Not nullable, causes crash if connection fails
late final EventsListener listener;

@OverRide
void onInit() async { // ❌ async void - cannot catch errors
await connectToRoom(); // If this fails, next line crashes
liveKitRoom.addListener(onRoomDidUpdate); // ❌ LateInitializationError!
setUpListeners();
if (isLiveChapter) {
listenToRecordingStateChanges();
}
super.onInit(); // ❌ Should be called first, synchronously
}
}
Steps to Reproduce:
Turn off WiFi/mobile data on your device
Open the Resonate app and log in
Navigate to any active room and try to join
Observe the crash
The Error Message
════════ Exception caught by widgets library ═══════════════════════════════════
The following LateError was thrown building:
LateInitializationError: Field 'liveKitRoom' has not been initialized.

When the exception was thrown, this was the stack:
#0 LiveKitController.liveKitRoom (package:resonate/controllers/livekit_controller.dart)
#1 LiveKitController.onInit (package:resonate/controllers/livekit_controller.dart:36)
#2 GetxController.onStart (package:get/get_state_manager/src/simple/get_controllers.dart:113)
════════════════════════════════════════════════════════════════

Expected Behavior
✅ App should NOT crash when connection fails
✅ User should see a clear error message: "Unable to connect to room. Please check your internet connection."
✅ App should remain functional and allow user to retry or go back
✅ Proper cleanup should occur even on connection failure

Actual Behavior:
❌ App crashes with LateInitializationError
❌ No error message shown to user
❌ User must force-quit and restart the app
❌ Poor user experience

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions