stripe / stripe-terminal-android

Stripe Terminal Android SDK
https://stripe.dev/stripe-terminal-android/
Other
93 stars 46 forks source link

TerminalException thrown for bluetooth readers #496

Closed wkol closed 2 months ago

wkol commented 2 months ago

Summary

After upgrading the SDK to version 3.9.0 we started observing a large amount of crashes with the following stack trace:

   Fatal Exception: com.stripe.stripeterminal.external.models.TerminalException: Bluetooth scan timed out
       at com.stripe.stripeterminal.internal.common.adapter.BbposBluetoothAdapter$DiscoverBluetoothReadersOperation.createTimeoutException(BbposBluetoothAdapter.kt:567)
       at com.stripe.stripeterminal.internal.common.adapter.BbposAdapter$DiscoverReadersOperation$timeoutFlow$1.invokeSuspend(BbposAdapter.kt:1159)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
       at java.lang.Thread.run(Thread.java:1012)

This happens when the discovery process for Bluetooth readers (e.g. M2) results in a timeout. Firstly, the exception is passed to the callback onFailure, but later, it is also thrown.

Code to reproduce

Terminal.getInstance().discoverReaders(
    config =  DiscoveryConfiguration.BluetoothDiscoveryConfiguration(
            timeout = 5,
            isSimulated = false
        )
    discoveryListener = discoveryListener,
    callback = callback
)

Android version

12, 13, 14 (but I suppose it is not a version-specific problem)

Impacted devices (Android devices or readers)

Bluetooth readers (e.g M2) Internet readers seems fine

SDK version

3.9.0, but checked on 3.9.1 and it still occurs

nk-stripe commented 2 months ago

Hi, thanks for posting this issue. We’ve reproduced the problem and are actively working on a fix.

usaimbhayat-stripe commented 2 months ago

Hi @wkol, issue is now fixed in the 3.9.2 release.

Ekalips commented 2 months ago

Hi @usaimbhayat-stripe , the issue is still reproducible on 3.9.2

com.stripe.stripeterminal.external.models.TerminalException: Bluetooth scan timed out
    at com.stripe.stripeterminal.internal.common.adapter.BbposBluetoothAdapter$DiscoverBluetoothReadersOperation.createTimeoutException(BbposBluetoothAdapter.kt:567)
    at com.stripe.stripeterminal.internal.common.adapter.BbposAdapter$DiscoverReadersOperation$timeoutFlow$1.invokeSuspend(BbposAdapter.kt:1159)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
    at java.lang.Thread.run(Thread.java:1012)
    Suppressed: kotlinx.coroutines.flow.internal.AbortFlowException: Flow was aborted, no more elements needed
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [CoroutineName(Transaction), LazyStandaloneCoroutine{Cancelling}@6f8076c, java.util.concurrent.Executors$FinalizableDelegatedExecutorService@3664135]
billfinn-stripe commented 2 months ago

Hi @Ekalips -- thanks. It looks like the fix didn't make it into the 3.9.2 release. We're working on fixing this now, and we're planning on releasing a 3.9.3.

usaimbhayat-stripe commented 2 months ago

Hi @wkol @Ekalips, we have just released 3.9.3 to address this bug. We've done our best to thoroughly test this, please let us know if you still have issues.