eclipse-hara / hara-ddiclient

Hara-ddiclient is a Kotlin library that facilitates and speeds up the development of DDI API clients for devices connecting to hawkBit servers.
https://projects.eclipse.org/projects/iot.hawkbit.hara
Eclipse Public License 2.0
18 stars 13 forks source link

Crash after re-invoking startAsync() after stop() function is called #54

Open N7k opened 3 months ago

N7k commented 3 months ago

Hello!

We are utilizing the Eclipse Hara DDIClient library alongside the HawkBit server to perform OTA updates on our devices. Our implementation adheres to the examples provided in the repository. The update process works well with the startAsync() function. However, we encounter issues when using the stop() function. Let me describe the process in detail.

  1. We invoke the startAsync() function to begin the OTA update process.
  2. During the update, if we call the stop() function to interrupt the process (e.g., when a file has started downloading), for instance, by UX needs, then re-invoke startAsync() (after reinitializing the HaraClient as per the documentation), and at some point during the following downloading process, the application crashes.

Steps to Reproduce:

  1. Initialize the HaraClient.
  2. Call startAsync() to begin the OTA update process.
  3. During the update (e.g., when a file is downloading), call the stop() function to interrupt the process.
  4. Reinitialize the HaraClient.
  5. Call startAsync() again, then wait.

The application crashes with the following exception:

FATAL EXCEPTION: DefaultDispatcher-worker-4
Process: com.hara.test.haratest, PID: 1206
kotlinx.coroutines.channels.ClosedSendChannelException: Channel was closed
    at kotlinx.coroutines.channels.Closed.getSendException(AbstractChannel.kt:1107)
    at kotlinx.coroutines.channels.AbstractSendChannel.helpCloseAndResumeWithSendException(AbstractChannel.kt:230)
    at kotlinx.coroutines.channels.AbstractSendChannel.access$helpCloseAndResumeWithSendException(AbstractChannel.kt:19)
    at kotlinx.coroutines.channels.AbstractSendChannel.sendSuspend(AbstractChannel.kt:220)
    at kotlinx.coroutines.channels.AbstractSendChannel.send(AbstractChannel.kt:136)
    at kotlinx.coroutines.channels.ChannelCoroutine.send(Unknown Source:2)
    at org.eclipse.hara.ddiclient.api.actors.FileDownloader.feedback(FileDownloader.kt:178)
    at org.eclipse.hara.ddiclient.api.actors.FileDownloader.access$feedback(FileDownloader.kt:31)
    at org.eclipse.hara.ddiclient.api.actors.FileDownloader$checkDownloadProgress$1$1.invokeSuspend(FileDownloader.kt:161)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
    Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@1f2110f, Dispatchers.Default]

Additionally, after calling the stop() function, the following logs appear:

2024-07-25 11:30:57.237   946-1029  System.err              com.hara.test.haratest               W  [DefaultDispatcher-worker-5] INFO org.eclipse.hara.ddiclient.api.actors.RootActor - Actor rootActor exiting.
2024-07-25 11:30:57.241   946-1029  System.err              com.hara.test.haratest               W  [DefaultDispatcher-worker-5] INFO org.eclipse.hara.ddiclient.api.actors.NotificationManager - Actor notificationManager exiting.
2024-07-25 11:30:57.242   946-1078  System.err              com.hara.test.haratest               W  [DefaultDispatcher-worker-4] INFO org.eclipse.hara.ddiclient.api.actors.ConnectionManager - Actor connectionManager exiting.
2024-07-25 11:30:57.245   946-1030  System.err              com.hara.test.haratest               W  [DefaultDispatcher-worker-6] INFO org.eclipse.hara.ddiclient.api.actors.ActionManager - Actor actionManager exiting.
2024-07-25 11:31:19.229   946-1030  System.err              com.hara.test.haratest               W  [DefaultDispatcher-worker-6] ERROR org.eclipse.hara.ddiclient.api.actors.DownloadManager - Error processing message in actor downloadManager, actor exiting. error: class java.util.concurrent.CancellationException message: ActorCoroutine was cancelled
2024-07-25 11:31:19.230   946-1078  System.err              com.hara.test.haratest               W  [DefaultDispatcher-worker-4] ERROR org.eclipse.hara.ddiclient.api.actors.DeploymentManager - Error processing message in actor deploymentManager, actor exiting. error: class java.util.concurrent.CancellationException message: ActorCoroutine was cancelled
2024-07-25 11:31:19.233   946-1078  System.err              com.hara.test.haratest               W  [DefaultDispatcher-worker-4] ERROR org.eclipse.hara.ddiclient.api.actors.UpdateManager - Error processing message in actor updateManager, actor exiting. error: class kotlinx.coroutines.JobCancellationException message: Parent job is Cancelling

Environment:

Library version: 2.0.0 Android version: 34 Devices: Emulators, EVT Device

diegorondini commented 3 months ago

Hello @N7k

thanks for reporting this issue!

Can you please try the latest build from the dev branch (https://github.com/eclipse-hara/hara-ddiclient/tree/dev) that includes a fix for this? https://jitpack.io/#eclipse-hara/hara-ddiclient/dev-de34262b2d-1

Looking forward to your feedback.

N7k commented 2 months ago

Hello @diegorondini,

Sorry for the delayed response, and thank you for addressing the issue! I've tested the latest build from the dev branch and am pleased to confirm that it resolves the problem. Everything appears to be working smoothly now.

Could you also let me know when the next official release is planned? It would be helpful for our deployment timeline.

Thanks again for your support!