Skip to content

[FLW-Mobile-App] Bug: Prevent StackOverflowError by limiting recursive retries on SocketTimeoutException #156

@vibhutomer

Description

@vibhutomer

Description:
Currently, within the FLW-Mobile-App codebase, several repository classes contain network calls that catch a SocketTimeoutException and recursively call themselves to retry the fetch. Because there is no limit or counter on this recursion, a persistent network timeout will trigger an infinite loop, ultimately crashing the mobile application with a StackOverflowError.

Affected Files & Functions (in FLW-Mobile-App):

  • IncentiveRepo.kt -> pullAndSaveAllIncentiveActivities()
  • IncentiveRepo.kt -> pullAndSaveAllIncentiveRecords()

Expected Behavior:
The application should attempt to retry a failed network call a reasonable number of times (e.g., 3 attempts) before failing gracefully and returning an error state to the UI. This prevents memory exhaustion and fatal crashes for field workers with poor connectivity.

Suggested Fix:
Modify the function signatures to include a default parameter retryCount: Int = 3. Inside the catch (e: SocketTimeoutException) block, check if retryCount > 0. If true, make the recursive call passing retryCount - 1. If false, return a default failure value (like false or -1) or emit an error state.

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