Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import java.lang.reflect.Field
Expand Down Expand Up @@ -645,10 +646,18 @@ class MapboxNavigation @VisibleForTesting internal constructor(
* navigation simulation, or before resetting location to not real (simulated)
* position without recreation of [MapboxNavigation].
*/
@Deprecated(message = "use a function withe the callback instead")
@Deprecated(message = "use the overload with the callback instead")
fun resetTripSession() {
resetTripSession {
// no-op
// using a blocking function to keep parity with the original implementation so that
// Nav Native is fully done with the reset when this function returns
runBlocking {
Copy link
Contributor

@VysotskiVadim VysotskiVadim Dec 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LukasPaczos , from the first glance it seems like it should always cause a deadlock:

  1. User calls MapboxNavigation#resetTripSession() from a main thread
  2. runBlocking stops and holds main thread until it receives callback from NN
  3. NN does some heavy actions and posts callback to main thread via events queue
  4. Event's queue aren't processes because main thread has stopped during step 2

I was surprised that it works and it turned out that NN calls the callback from their worker thread without rescheduling to the main thread, which is not typical for NN's API. Do you think it's safe to rely on this implementation detail of NN? I worry that if they change it, deprecated version of resetTripSession will always cause a deadlock.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for raising this. In the end no, we shouldn't really rely on this. This is a strong enough reason to try and find a different approach or work with Nav Native to leave the old function be, even if deprecated.

Tracking in NAVAND-984.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a test as a safeguard that would block us from adopting a NN version that would break this logic - #6710.

logD(LOG_CATEGORY) {
"Resetting trip session"
}
navigator.resetRideSession()
logI(LOG_CATEGORY) {
"Trip session reset"
}
}
}

Expand Down