Skip to content

SqlConnection crashes on Google Play #3363

Closed

Description

@jrahma

Hi,

I have deployed this app to Google Play store:

https://play.google.com/store/apps/details?id=com.jafaria.official

The app works beautiful when I use it on Emulator. It also works perfectly when I deploy from Visual Studio to the device

But my problem started only when I install the app from Google Play.

The problem is like this..

I have a rotator in the home page populating data from SqlServer's SqlConnection and this part is working fine but when I open any second page which has data fromSqlConnection then the app will crash with this error in AppCenter:

AppCenterLog.Error (System.String p0, System.String p1)
Java.Lang.OutOfMemoryError: Failed to allocate a 5118169368 byte allocation with 6291456 free bytes and 509MB until OOM, max allowed footprint 9207128, growth limit 536870912
O

opening static pages has no issue but it's only when opening pages with SqlConnection such as news page (see the icon for guide)

You can try downloading the app from Google Play and click on any of these icons and the app will crash

Screenshot_20190717_232028_com jafaria official

Thanks,
Jassim

Activity

  1. added
    need-info
    on Jul 18, 2019
  2. added this to the Under Consideration milestone on Jul 18, 2019
  3. self-assigned this
    on Jul 18, 2019
  4. grendello commented on Jul 18, 2019

    @grendello
    Contributor

    Hi Jassim,

    I'm guessing the error is shown as happening on some device for some user who downloaded the app? Do you know what the device is? Would you be able to test it personally? In general, the problem is that something in your application tries to allocate nearly 5GB of RAM which is unlikely to work in most cases. Unfortunately, the information you provided is not sufficient to see where the allocation happens. If you can get a full stack trace of the OOM crash and, ideally, a logcat of the failed session then we might be able to figure out what is going on. We don't know if the allocation is attempted in Java or .NET code, the trace mentioned before would be necessary to determine that.

    Please provide the requested information and we'll try to figure out the issue, thanks!

  5. jrahma commented on Jul 18, 2019

    @jrahma
    Author

    I tried it so far on Honor Lite 10 (my device) and Mate 20 Pro (another user device) and both are giving the same problem.

    and as I said it's working perfectly when I just deploy the apk on my device locally (the same Honor 10 Lite) or run it on emulator

    This is a sample code which I don't think it should consume 5GB!

    try
    {
        SearchBoxServices.IsVisible = false;
        ListViewServices.IsVisible = false;
    
        loadingServices.IsVisible = true;
    
        sql_connection = new SqlConnection("Server=my.server.com; Database=myDB; User Id=myUser; Password=myPassword;");
        await sql_connection.OpenAsync();
        // sql_connection.Open();
    
        sql_command = new SqlCommand("sp_get_my_sp", sql_connection);
        sql_command.CommandType = CommandType.StoredProcedure;
        SqlDataReader sql_reader = await sql_command.ExecuteReaderAsync();
    
        ObservableCollection<object> trends = new ObservableCollection<object>();
    
        while (sql_reader.Read())
        {
            ServicesData data1 = new ServicesData()
            {
                service_code = Convert.ToString(sql_reader["service_code"]),
                service_name = Convert.ToString(sql_reader["service_name"]),
                service_description = Convert.ToString(sql_reader["service_description"]),
            };
    
            trends.Add(data1);
        }
    
        ListViewServices.ItemsSource = trends;
    
        loadingServices.IsVisible = false;
    
        SearchBoxServices.IsVisible = true;
        ListViewServices.IsVisible = true;
    }
    catch (HttpRequestException ex)
    {
        await DisplayAlert("Error", ex.StackTrace, "Ok");
    
        Crashes.TrackError(ex, new Dictionary<string, string>
        {
            { "Page", this.Title },
            { "Where", "GetServices" }
        });
    
        loadingServices.IsVisible = false;
        SearchBoxServices.IsVisible = false;
        ListViewServices.IsVisible = false;
    
        ServicesNoInternet.IsVisible = true;
    
        return;
    }
    catch (Exception ex)
    {
        Crashes.TrackError(ex, new Dictionary<string, string>
        {
            { "Page", this.Title },
            { "Where", "GetServices" }
        });
    
        loadingServices.IsVisible = false;
        SearchBoxServices.IsVisible = false;
        ListViewServices.IsVisible = false;
    
        ServicesNoInternet.IsVisible = true;
    
        return;
    }
    
    
    
  6. jrahma commented on Jul 18, 2019

    @jrahma
    Author

    This is from AppCenter:

    JniEnvironment+Strings.NewString (System.Char* unicodeChars, System.Int32 length)
    JniEnvironment+Strings.NewString (System.String value)
    JNIEnv.NewString (System.String text)
    AppCenterLog.Error (System.String p0, System.String p1)
    AppCenterLog.Error (System.String tag, System.String message)
    AppCenterLog.Error (System.String tag, System.String message, System.Exception exception)
    Crashes.OnUnhandledException (System.Exception exception, System.String source)
    Crashes.OnUnhandledException (System.Object sender, Android.Runtime.RaiseThrowableEventArgs e)
    AndroidEnvironment.UnhandledException (System.Exception e)
    (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.74(intptr,intptr,intptr,intptr,intptr)
    (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.74(intptr,intptr,intptr,intptr,intptr)
    java.lang.OutOfMemoryError: Failed to allocate a 5118169368 byte allocation with 3062271 free bytes and 509MB until OOM, max allowed footprint 6124543, growth limit 536870912
    md58432a647068b097f9637064b8985a5e0.FragmentContainer.n_onCreateView(Native Method)
    md58432a647068b097f9637064b8985a5e0.FragmentContainer.onCreateView(:33)
    android.support.v4.app.Fragment.performCreateView(:2439)
    android.support.v4.app.FragmentManagerImpl.moveToState(:1460)
    android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(:1784)
    android.support.v4.app.FragmentManagerImpl.moveToState(:1852)
    android.support.v4.app.BackStackRecord.executeOps(:802)
    android.support.v4.app.FragmentManagerImpl.executeOps(:2625)
    android.support.v4.app.FragmentManagerImpl.executeOpsTogether(:2411)
    android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(:2366)
    android.support.v4.app.FragmentManagerImpl.execPendingActions(:2273)
    android.support.v4.app.FragmentManagerImpl$1.run(:733)
    android.os.Handler.handleCallback(Handler.java:891)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:207)
    android.app.ActivityThread.main(ActivityThread.java:7470)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)

  7. grendello commented on Aug 20, 2019

    @grendello
    Contributor

    hi @jrahma, the sample code looks almost innocuous, indeed. However, the Convert.ToString calls have at least he potential of runaway allocation (should sqlite be buggy, database corrupted etc) since it appears to be a single, big allocation attempt. Can you add some Console.WriteLine statements before and after those lines to see where exactly the exception is thrown? It might be a good idea to surround every line potentially allocating memory with Console.WriteLine - that way we should be able to see in logcat at least what's the sequence leading to the OOM.

  8. grendello commented on Aug 20, 2019

    @grendello
    Contributor

    @jrahma looking at your stack trace we noticed that there's a FragmentContainer implementation in your app - do you do any large allocations in a subclass of it? Also, some questions:

    • Is your emulator 64-bit or 32-bit?
    • Is your emulator x86 or ARM?
    • Are the devices you tested on 32-bit or 64-bit?
    • Does your app have 64-bit targets enabled?

    The huge allocation size might be result of signed to unsigned integer conversion, something similar to:

    int i = -1;
    uint j = (uint)i;

    Which would yield the value of 4294967295 in j - if then that value is added to some ulong or long, it may very well result in the 5GB allocation we're seeing.

  9. jonathanpeppers commented on Sep 23, 2019

    @jonathanpeppers
    Member

    @jrahma closing for now as we haven't heard back in a while.

    If you know the answer's to @grendello's questions we can look into it further, thanks!

  10. ghost locked as resolved and limited conversation to collaborators on Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

need-info

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions