简体   繁体   中英

Can't catch MySqlConnection Open()

I am developing a Xamarin.Android app and I am using a remote MySql database (AWS). The connection works perfectly fine and there is no problem with it. But when the user has no connection (testing with airplane mode) it crashes and there is no way I can catch it.

I am using a custom class to manage the database connections. Using MySqlConnector and I already tried catching MySqlException.

private MySqlConnection CreateOpenConnection()
{
    try
    {
        if (string.IsNullOrWhiteSpace(connectionString)) throw new Exception("Connection string must not be empty");
        MySqlConnection conn = new MySqlConnection(connectionString);
        if (conn != null)
        {
            conn.Open();
            return conn;
        }
        else throw new Exception("Failed to open connection");
    }
    catch(MySqlException mex)
    {
        Log.Error(Tags.LogTag, string.Format("Exception caught while {0}. \nMessage = {1}\nStack: {2}", "creating open connection", mex.Message, mex.StackTrace));
        return null;
    }
    catch(InvalidOperationException ioe)
    {
        Log.Error(Tags.LogTag, string.Format("Exception caught while {0}. \nMessage = {1}\nStack: {2}", "creating open connection", ioe.Message, ioe.StackTrace));
        return null;
    }
    catch (Exception thisEx)
    {
        Log.Error(Tags.LogTag, string.Format("Exception caught while creating open connection. Message = {0}", thisEx.Message));
        return null;
    }
}

When debugging, when it executes the line conn.Open(); debugging stops and the application instantly closes, no execption is raised or caught, either any message is shown in Visual Studio. This kind of behavior happens when the app enters in an infinite loop, but that can't be the case.

If it helps, Visual Studio output window shows this:

=================================================================
    Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
    Basic Fault Adddress Reporting
=================================================================
Memory around native instruction pointer (0x766300b678):0x766300b668  00 1c 40 b9 c0 03 5f d6 fd 7b bf a9 fd 03 00 91  ..@..._..{......
0x766300b678  08 20 40 b9 a8 00 c8 37 88 01 e0 37 00 00 40 f9  . @....7...7..@.
0x766300b688  fd 7b c1 a8 c0 03 5f d6 60 08 00 b0 01 0a 00 f0  .{...._.`.......
0x766300b698  03 0a 00 f0 00 24 06 91 21 80 08 91 63 8c 0a 91  .....$..!...c...

No native Android stacktrace (see debuggerd output).

=================================================================
    Managed Stacktrace:
=================================================================
      at <unknown> <0xffffffff>
      at System.Threading._ThreadPoolWaitCallback:PerformWaitCallback <0x00007>
      at <Module>:runtime_invoke_bool <0x0006f>
=================================================================

Logcat shows this when the app crashes:

06-01 19:22:02.091: E/mono-rt(26412): /proc/self/maps:
06-01 19:22:02.091: E/mono-rt(26412): 12c00000-13640000 rw-p 00000000 00:04 52628                              /dev/ashmem/dalvik-main space (region space) (deleted)
06-01 19:22:02.091: E/mono-rt(26412): 13640000-13f40000 ---p 00a40000 00:04 52628                              /dev/ashmem/dalvik-main space (region space) (deleted)
06-01 19:22:02.091: E/mono-rt(26412): 13f40000-1b200000 rw-p 01340000 00:04 52628                              /dev/ashmem/dalvik-main space (region space) (deleted)
06-01 19:22:02.091: E/mono-rt(26412): 1b200000-1b240000 ---p 08600000 00:04 52628                              /dev/ashmem/dalvik-main space (region space) (deleted)
06-01 19:22:02.091: E/mono-rt(26412): 1b240000-2ac00000 rw-p 08640000 00:04 52628                              /dev/ashmem/dalvik-main space (region space) (deleted)
06-01 19:22:02.091: E/mono-rt(26412): 70d51000-70d64000 rw-p 00000000 fc:01 548870                             /data/dalvik-cache/arm64/system@framework@boot.art
06-01 19:22:02.091: E/mono-rt(26412): 70d64000-70d66000 r--p 00013000 fc:01 548870                             /data/dalvik-cache/arm64/system@framework@boot.art
06-01 19:22:02.091: E/mono-rt(26412): 70d66000-70d72000 rw-p 00000000 fc:01 548876                             /data/dalvik-cache/arm64/system@framework@boot-qcom.fmradio.art
06-01 19:22:02.091: E/mono-rt(26412): 70d72000-70d73000 r--p 0000c000 fc:01 548876                             /data/dalvik-cache/arm64/system@framework@boot-qcom.fmradio.art
06-01 19:22:02.091: E/mono-rt(26412): 70d73000-70d74000 rw-p 00000000 fc:01 548879                             /data/dalvik-cache/arm64/system@framework@boot-com.qualcomm.qti.camera.art
06-01 19:22:02.091: E/mono-rt(26412): 70d74000-70d75000 r--p 00001000 fc:01 548879                             /data/dalvik-cache/arm64/system@framework@boot-com.qualcomm.qti.camera.art
06-01 19:22:02.091: E/mono-rt(26412): 70d75000-70d77000 rw-p 00000000 fc:01 548885                             /data/dalvik-cache/arm64/system@framework@boot-QPerformance.art
06-01 19:22:02.091: E/mono-rt(26412): 70d77000-70d78000 r--p 00002000 fc:01 548885                             /data/dalvik-cache/arm64/system@framework@boot-QPerformance.art
06-01 19:22:02.091: E/mono-rt(26412): 70d78000-70d79000 rw-p 00000000 fc:01 548891                             /data/dalvik-cache/arm64/system@framework@boot-UxPerformance.art
06-01 19:22:02.091: E/mono-rt(26412): 70d79000-70d7a000 r--p 00001000 fc:01 548891                             /data/dalvik-cache/arm64/system@framework@boot-UxPerformance.art
06-01 19:22:02.091: E/mono-rt(26412): 70d7a000-71104000 rw-p 00000000 fc:01 548900                             /data/dalvik-cache/arm64/system@framework@boot-core-oj.art
06-01 19:22:02.091: E/mono-rt(26412): 71104000-71118000 r--p 0038a000 fc:01 548900                             /data/dalvik-cache/arm64/system@framework@boot-core-oj.art
06-01 19:22:02.091: E/mono-rt(26412): 71118000-712d2000 rw-p 00000000 fc:01 548909                             /data/dalvik-cache/arm64/system@framework@boot-core-libart.art
06-01 19:22:02.091: E/mono-rt(26412): 712d2000-712e4000 r--p 001ba000 fc:01 548909                             /data/dalvik-cache/arm64/system@framework@boot-core-libart.art
06-01 19:22:02.091: E/mono-rt(26412): 712e4000-71330000 rw-p 00000000 fc:01 548915                             /data/dalvik-cache/arm64/system@framework@boot-conscrypt.art
06-01 19:22:02.091: E/mono-rt(26412): 71330000-71333000 r--p 0004c000 fc:01 548915                             /data/dalvik-cache/arm64/system@framework@boot-conscrypt.art
06-01 19:22:02.091: E/mono-rt(26412): 71333000-7137a000 rw-p 00000000 fc:01 548918                             /data/dalvik-cache/arm64/system@framework@boot-okhttp.art
06-01 19:22:02.091: E/mono-rt(26412): 7137a000-7137d000 r--p 00047000 fc:01 548918                             /data/dalvik-cache/arm64/system@framework@boot-okhttp.art
06-01 19:22:02.091: E/mono-rt(26412): 7137d000-713fe000 rw-p 00000000 fc:01 548927                             /data/dalvik-cache/arm64/system@framework@boot-bouncycastle.art
06-01 19:22:02.091: E/mono-rt(26412): 713fe000-71405000 r--p 00081000 fc:01 548927                             /data/dalvik-cache/arm64/system@framework@boot-bouncycastle.art
06-01 19:22:02.092: A/libc(26412): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x20 in tid 26472 (Thread Pool Wor), pid 26412 (.keeptravelling)
06-01 19:22:02.182: E/DEBUG(26707): failed to readlink /proc/26472/fd/115: No such file or directory
06-01 19:22:02.268: W/crash_dump64(26707): failed to attach to thread 26702: No such process
06-01 19:22:02.268: E/crash_dump64(26707): failed to interrupt 26702 to detach: No such process
06-01 19:22:02.268: W/crash_dump64(26707): failed to ptrace interrupt thread 26702: No such process
06-01 19:22:02.292: E/WakeLock(15163): GCM_HB_ALARM release without a matched acquire!
06-01 19:22:02.292: W/WakeLock(15163): GCM_HB_ALARM counter does not exist
06-01 19:22:02.294: E/WakeLock(15163): GCM_CONN_ALARM release without a matched acquire!
06-01 19:22:02.311: I/crash_dump64(26707): obtaining output fd from tombstoned, type: kDebuggerdTombstone
06-01 19:22:02.317: I//system/bin/tombstoned(2430): received crash request for pid 26472
06-01 19:22:02.319: I/crash_dump64(26707): performing dump of process 26412 (target tid = 26472)
06-01 19:22:02.324: D/SharedPreferencesImpl(26412): Time required to fsync /data/user/0/fib.smascaro.keeptravelling/shared_prefs/com.google.android.gms.measurement.prefs.xml: [<1: 0, <2: 0, <4: 1, <8: 1, <16: 0, <32: 0, <64: 0, <128: 0, <256: 1, <512: 1, <1024: 0, <2048: 0, <4096: 0, <8192: 0, <16384: 0, >=16384: 0]
06-01 19:22:02.338: A/DEBUG(26707): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-01 19:22:02.338: A/DEBUG(26707): Build fingerprint: 'xiaomi/tissot/tissot_sprout:9/PKQ1.180917.001/V10.0.9.0.PDHMIXM:user/release-keys'
06-01 19:22:02.338: A/DEBUG(26707): Revision: '0'
06-01 19:22:02.338: A/DEBUG(26707): ABI: 'arm64'
06-01 19:22:02.338: A/DEBUG(26707): pid: 26412, tid: 26472, name: Thread Pool Wor  >>> fib.smascaro.keeptravelling <<<
06-01 19:22:02.338: A/DEBUG(26707): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x20
06-01 19:22:02.338: A/DEBUG(26707): Cause: null pointer dereference
06-01 19:22:02.338: A/DEBUG(26707):     x0  0000000000000000  x1  0000000000000000  x2  0000000000000000  x3  00000076573f38b0
06-01 19:22:02.338: A/DEBUG(26707):     x4  0000007657e9e9a0  x5  00000076573f3940  x6  0000000000000000  x7  0000000000000000
06-01 19:22:02.338: A/DEBUG(26707):     x8  0000000000000000  x9  0000000000000000  x10 0000000000000000  x11 0000000000000000
06-01 19:22:02.338: A/DEBUG(26707):     x12 0000000000000000  x13 0000000000000000  x14 0000000000000000  x15 aaaaaaaaaaaaaaab
06-01 19:22:02.338: A/DEBUG(26707):     x16 00000076631e41f8  x17 000000766300b670  x18 00000076580837c8  x19 00000076631fb560
06-01 19:22:02.338: A/DEBUG(26707):     x20 0000000000000002  x21 0000000000000000  x22 0000000000000002  x23 0000000000000076
06-01 19:22:02.339: A/DEBUG(26707):     x24 0000000000000000  x25 0000000000000000  x26 00000076573f3a30  x27 0000007653af07d8
06-01 19:22:02.339: A/DEBUG(26707):     x28 0000007657e9e000  x29 00000076573f2d50
06-01 19:22:02.339: A/DEBUG(26707):     sp  00000076573f2d50  lr  0000007662f52658  pc  000000766300b678
06-01 19:22:02.340: A/DEBUG(26707): backtrace:
06-01 19:22:02.340: A/DEBUG(26707):     #00 pc 0000000000177678  /data/app/fib.smascaro.keeptravelling-gmskKOoZ0XLx3XQnXfD0Dw==/lib/arm64/libmonosgen-2.0.so (mono_jit_info_get_method+8)

Any help is welcome.

Thanks.

EDIT: added logcat output

Finally after some weeks facing this issue, found out it is a Mono.Android bug.

To solve it I updated Xamarin.Android SDK to 9.3.0.23, not a stable or official version, but refer to this Github filed issue.

The link is in this comment .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM