Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

CachingHttpFileSource crashes on Android #691

Closed

Description

@ljbade

@mikemorris I am seeing this crash at startup in the Android app:

#0  0x40163048 in tgkill () from /home/leith/mb/android-nexus/system_lib/libc.so
#1  0x4015409c in pthread_kill () from /home/leith/mb/android-nexus/system_lib/libc.so
#2  0x401542b0 in raise () from /home/leith/mb/android-nexus/system_lib/libc.so
#3  0x40152fe6 in ?? () from /home/leith/mb/android-nexus/system_lib/libc.so
#4  0x40162900 in abort () from /home/leith/mb/android-nexus/system_lib/libc.so
#5  0x6ba0aba4 in uv_mutex_lock () from /home/leith/mb/mbgl-android/build/android/out/Debug/lib.target/libmapbox-gl.so
#6  0x6b85f1a4 in uv_messenger_send () from /home/leith/mb/mbgl-android/build/android/out/Debug/lib.target/libmapbox-gl.so
#7  0x6b670210 in mbgl::CachingHTTPFileSource::prepare(std::__1::function<void ()>) (this=0x66f8a028, fn=...)
    at ../../platform/default/caching_http_file_source.cpp:103
#8  0x6b7a6f40 in mbgl::Map::setReachability (this=0x66f8a070, reachable=true) at ../../src/map/map.cpp:373
#9  0x6b64266c in (anonymous namespace)::nativeSetReachability (env=0x40135008, obj=0x19000019, nativeMapViewPtr=1727569936, 
    status=1 '\001') at ../../android/cpp/jni.cpp:702
#10 0x417f6bd0 in dvmPlatformInvoke () from /home/leith/mb/android-nexus/system_lib/libdvm.so
#11 0x41827126 in dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*) ()
   from /home/leith/mb/android-nexus/system_lib/libdvm.so
#12 0x41800028 in dvmJitToInterpNoChain () from /home/leith/mb/android-nexus/system_lib/libdvm.so
#13 0x41800028 in dvmJitToInterpNoChain () from /home/leith/mb/android-nexus/system_lib/libdvm.so
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Activity

  1. added
    Android
    on Dec 4, 2014
  2. mikemorris commented on Dec 4, 2014

    @mikemorris
    Contributor

    Possibly caused by/related to #686 (comment)?

  3. ljbade commented on Dec 4, 2014

    @ljbade
    ContributorAuthor

    Possibly, but I am not app switcing, just opening the app for the first time.

  4. jfirebaugh commented on Dec 4, 2014

    @jfirebaugh
    Contributor

    Does it call Map::setReachability before Map::start or Map::setStyleJSON?

  5. jfirebaugh commented on Dec 4, 2014

    @jfirebaugh
    Contributor

    @ljbade Merge 16fe8e6 and see if that resolves this.

  6. ljbade commented on Dec 5, 2014

    @ljbade
    ContributorAuthor

    Yeah I think that could happen, let me check.

  7. ljbade commented on Dec 5, 2014

    @ljbade
    ContributorAuthor

    @jfirebaugh now I get:

    #0  0x40163048 in tgkill () from /home/leith/mb/android-nexus/system_lib/libc.so
    #1  0x4015409c in pthread_kill () from /home/leith/mb/android-nexus/system_lib/libc.so
    #2  0x401542b0 in raise () from /home/leith/mb/android-nexus/system_lib/libc.so
    #3  0x40152fe6 in ?? () from /home/leith/mb/android-nexus/system_lib/libc.so
    #4  0x40162900 in abort () from /home/leith/mb/android-nexus/system_lib/libc.so
    #5  0x40153acc in ?? () from /home/leith/mb/android-nexus/system_lib/libc.so
    #6  0x40153044 in __assert2 () from /home/leith/mb/android-nexus/system_lib/libc.so
    #7  0x6b446de4 in mbgl::CachingHTTPFileSource::request (this=0x66f8718c, type=mbgl::JSON, url_=...)
        at ../../src/mbgl/storage/caching_http_file_source.cpp:72
    #8  0x6b534c8c in mbgl::Map::prepare (this=0x66f871e0) at ../../src/mbgl/map/map.cpp:702
    #9  0x6b53460c in mbgl::Map::run (this=0x66f871e0) at ../../src/mbgl/map/map.cpp:291
    #10 0x6b53b544 in operator() (this=0x6876daf8) at ../../src/mbgl/map/map.cpp:206
    #11 0x6b53b30c in std::__1::__thread_proxy<std::__1::tuple<mbgl::Map::start(bool)::$_6> >(void*) (__vp=0x6876daf8)
        at /home/leith/mb/mbgl-android/mason_packages/.android-platform//bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../include/c++/4.9/memory:2607
    #12 0x4014e22c in __thread_entry () from /home/leith/mb/android-nexus/system_lib/libc.so
    #13 0x4014e3c4 in pthread_create () from /home/leith/mb/android-nexus/system_lib/libc.so
    #14 0x00000000 in ?? ()
    ``
    
  8. ljbade commented on Dec 8, 2014

    @ljbade
    ContributorAuthor

    Now am I getting different crashes:

    12-08 19:48:08.715  23634-23655/com.mapbox.mapboxgl.app A/libc﹕ ../../src/mbgl/storage/caching_http_file_source.cpp:72: virtual std::unique_ptr<Request> mbgl::CachingHTTPFileSource::request(mbgl::ResourceType, const std::string &): assertion "std::this_thread::get_id() == threadId" failed
    
    12-08 19:49:11.783  24766-24785/? A/libc﹕ ../../src/mbgl/storage/caching_http_file_source.cpp:72: virtual std::unique_ptr<Request> mbgl::CachingHTTPFileSource::request(mbgl::ResourceType, const std::string &): assertion "std::this_thread::get_id() == threadId" failed
    

    So much has been changed I don't really know what is going on here.

  9. ljbade commented on Dec 8, 2014

    @ljbade
    ContributorAuthor

    Another crash, this time when the app is closing:

    #0  0x401a2048 in tgkill () from /home/leith/mb/android-nexus/system_lib/libc.so
    #1  0x4019309c in pthread_kill () from /home/leith/mb/android-nexus/system_lib/libc.so
    #2  0x401932b0 in raise () from /home/leith/mb/android-nexus/system_lib/libc.so
    #3  0x40191fe6 in ?? () from /home/leith/mb/android-nexus/system_lib/libc.so
    #4  0x401a1900 in abort () from /home/leith/mb/android-nexus/system_lib/libc.so
    #5  0x40192acc in ?? () from /home/leith/mb/android-nexus/system_lib/libc.so
    #6  0x40192044 in __assert2 () from /home/leith/mb/android-nexus/system_lib/libc.so
    #7  0x6b466010 in uv_messenger_stop () from /home/leith/mb/mbgl-android/build/android/out/Debug/lib.target/libmapbox-gl.so
    #8  0x6b2b7594 in mbgl::CachingHTTPFileSource::clearLoop (this=0x66f24224) at ../../src/mbgl/storage/caching_http_file_source.cpp:41
    #9  0x6b3af730 in operator() (this=0x66fcfe24) at ../../src/mbgl/map/map.cpp:158
    #10 0x6b3af31c in __invoke<<lambda at ../../src/mbgl/map/map.cpp:150:59> &> (this=0x66fcfe24, __f=...)
        at /home/leith/mb/mbgl-android/mason_packages/.android-platform//bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../include/c++/4.9/__functional_base:413
    #11 std::__1::__function::__func<mbgl::Map::start(bool)::$_3, std::__1::allocator<mbgl::Map::start(bool)::$_3>, void ()>::operator()() (this=0x66fcfe20)
        at /home/leith/mb/mbgl-android/mason_packages/.android-platform//bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../include/c++/4.9/functional:1370
    #12 0x6b2a652c in std::__1::function<void ()>::operator()() const (this=0x66fcfe20)
        at /home/leith/mb/mbgl-android/mason_packages/.android-platform//bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../include/c++/4.9/functional:1756
    #13 0x6b2a6444 in uv::async::async_cb (a=0x6877e798) at ../../src/mbgl/util/uv_detail.hpp:81
    #14 0x6b600930 in uv__async_event () from /home/leith/mb/mbgl-android/build/android/out/Debug/lib.target/libmapbox-gl.so
    #15 0x6b600f08 in uv__async_io () from /home/leith/mb/mbgl-android/build/android/out/Debug/lib.target/libmapbox-gl.so
    #16 0x6b615fac in uv__io_poll () from /home/leith/mb/mbgl-android/build/android/out/Debug/lib.target/libmapbox-gl.so
    #17 0x6b601680 in uv_run () from /home/leith/mb/mbgl-android/build/android/out/Debug/lib.target/libmapbox-gl.so
    #18 0x6b3a58c0 in mbgl::Map::run (this=0x66f24278) at ../../src/mbgl/map/map.cpp:296
    #19 0x6b3ac798 in operator() (this=0x66fcfd80) at ../../src/mbgl/map/map.cpp:206
    #20 0x6b3ac560 in std::__1::__thread_proxy<std::__1::tuple<mbgl::Map::start(bool)::$_6> >(void*) (__vp=0x66fcfd80)
        at /home/leith/mb/mbgl-android/mason_packages/.android-platform//bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../include/c++/4.9/memory:2607
    #21 0x4018d22c in __thread_entry () from /home/leith/mb/android-nexus/system_lib/libc.so
    #22 0x4018d3c4 in pthread_create () from /home/leith/mb/android-nexus/system_lib/libc.so
    #23 0x00000000 in ?? ()
    
  10. ljbade commented on Dec 8, 2014

    @ljbade
    ContributorAuthor

    Also for some reason map tiles other than from the initial view do not get loaded. You can zoom in and pan but it only shows the initial tiles.

  11. ljbade commented on Dec 8, 2014

    @ljbade
    ContributorAuthor

    Saw a message about heap corruption:

    12-08 20:22:30.237    5258-5569/com.mapbox.mapboxgl.app A/libc﹕ ../../src/mbgl/storage/caching_http_file_source.cpp:72: virtual std::unique_ptr<Request> mbgl::CachingHTTPFileSource::request(mbgl::ResourceType, const std::string &): assertion "std::this_thread::get_id() == threadId" failed
    12-08 20:22:30.247    5258-5258/com.mapbox.mapboxgl.app A/libc﹕ heap corruption detected by dlfree
    
  12. ljbade commented on Dec 8, 2014

    @ljbade
    ContributorAuthor

    @jfirebaugh @mikemorris seems things have really gone downhill from when I had it pretty much stable last week

  13. jfirebaugh commented on Dec 8, 2014

    @jfirebaugh
    Contributor

    The uv_messenger_stop assertion failure suggests Map::stop may be getting called multiple times.

    Where's the code that creates CachingHTTPFileSource for android?

  14. ljbade commented on Dec 8, 2014

    @ljbade
    ContributorAuthor

    @jfirebaugh https://github.com/mapbox/mapbox-gl-native/blob/android-mason/android/cpp/native_map_view.cpp

    It is possible that stop gets called more than once, the Android lifecycle is very messed up with GL, need to check my debug print spew to see if it is

  15. mikemorris commented on Dec 8, 2014

    @mikemorris
    Contributor

    @jfirebaugh CachingHTTPFileSource is created at https://github.com/mapbox/mapbox-gl-native/blob/android-mason/android/cpp/native_map_view.cpp#L50

    This usage looks quite similar to how I'm creating the Map and FileSource objects in Node.js bindings, which required disabling a handful of asserts to get everything running. Longer-term fix for this probably involves revisiting the threading model in Map objects.

  16. ljbade commented on Dec 9, 2014

    @ljbade
    ContributorAuthor

    @mikemorris I tried your branch with the disabled asserts but I still get the clearLoop assert and still does not load tiles properly.

  17. mikemorris commented on Dec 9, 2014

    @mikemorris
    Contributor

    @ljbade I would expect the assert in clearLoop to fail. It should probably be removed, as that function can be called from the main loop in Map. @jfirebaugh removed the assert from setBase for the same reason 0c9ae49.

    Ultimately, clearLoop is still a hack, and we'll need to rework the threading model 36500b9

  18. jfirebaugh commented on Dec 9, 2014

    @jfirebaugh
    Contributor

    @mikemorris I believe that particular assert is correct, and failing it indicates a problem. There's what I'm calling the "main thread" and there's the thread that the event loop runs on. setLoop and clearLoop should only be called from the latter.

  19. mikemorris commented on Dec 9, 2014

    @mikemorris
    Contributor

    @jfirebaugh Oh, I'm getting a bit mixed up with all these threads, main != map.

    FileSource loop is only set in Map::prepare, and cleared in asyncTerminate. If the assert in asyncTerminate passes, then I would expect the assert in clearLoop to pass as well?

    EDIT: Is threadId set properly in setLoop? It's set to the id of the current thread, not the id of the loop thread?

  20. jfirebaugh commented on Dec 9, 2014

    @jfirebaugh
    Contributor

    I'm blocked from debugging this by #689.

  21. mikemorris commented on Dec 10, 2014

    @mikemorris
    Contributor

    Blocked by #689 as well.

  22. jfirebaugh commented on Dec 10, 2014

    @jfirebaugh
    Contributor

    Now blocked by #712.

  23. jfirebaugh commented on Dec 11, 2014

    @jfirebaugh
    Contributor
  24. added this to the Android merge milestone on Dec 17, 2014
  25. ljbade commented on Dec 18, 2014

    @ljbade
    ContributorAuthor

    After merging latest master everything seems to be working now. Haven't been able to bring back the crash and tiles now load properly.

    I think that loop fix was the trick.

  26. mikemorris commented on Dec 18, 2014

    @mikemorris
    Contributor

    Alright, that's great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Androidbug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions