mapbox / mapbox/mapbox-navigation-android
OOM exception building really long routes
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 651
- Forks
- 321
- PR merge metrics
- No merged PRs in 30d
Description
**Android API:any
**Mapbox Navigation SDK version:1.4.0
### Steps to trigger behavior
1. Build long route (thousand of kimoleters)
2. App crashes randomly, depending on memory of the device.
Crash happens within [DirectionsJsonObject](https://github.com/mapbox/mapbox-java/blob/master/services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/DirectionsJsonObject.java) at GSON serialization with the following stacktrace :
```
E/AndroidRuntime(11384): java.lang.OutOfMemoryError: Failed to allocate a 3690812 byte allocation with 2202366 free bytes and 2MB until OOM
E/AndroidRuntime(11384): at java.lang.String.(String.java:400)
E/AndroidRuntime(11384): at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:633)
E/AndroidRuntime(11384): at java.lang.StringBuffer.toString(StringBuffer.java:723)
E/AndroidRuntime(11384): at java.io.StringWriter.toString(StringWriter.java:100)
E/AndroidRuntime(11384): at com.google.gson.Gson.toJson(Gson.java:639)
E/AndroidRuntime(11384): at com.google.gson.Gson.toJson(Gson.java:618)
E/AndroidRuntime(11384): at com.mapbox.api.directions.v5.models.DirectionsJsonObject.toJson(DirectionsJsonObject.java:30)
E/AndroidRuntime(11384): at com.mapbox.navigation.navigator.internal.MapboxNativeNavigatorImpl$setRoute$2.invokeSuspend(MapboxNativeNavigatorImpl.kt:150)
E/AndroidRuntime(11384): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
E/AndroidRuntime(11384): at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
E/AndroidRuntime(11384): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/AndroidRuntime(11384): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/AndroidRuntime(11384): at java.lang.Thread.run(Thread.java:818)
```
From my analysis reason is that nav native implementation accepts route as a single string thus fails if string becomes really large.
While possible solutions are to pass some Json/Route object entity instead of string, temporary workaround returning some error instead of throwing an exception from background thread would also be nice.
cc @mapbox/navigation-android @mskurydin
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/DirectionsJsonObject.java and its toJson call, then trace MapboxNativeNavigatorImpl$setRoute$2 at line 150. Reproduce with a route thousands of kilometers long and inspect how the single-string route is passed; done should prevent the background-thread OutOfMemoryError or return an error instead.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100