Repository: godot
Issue: Mono godot_icall from Rpc from _Input causes crash
Labels: bug,topic:dotnet,crash

**Godot version:**
e21f808530b02a393a46d597afe89b4fbf886bb6


**OS/device including version:**
Arch Linux


**Issue description:**
This is a weird one. If you do an icall from within an RPC call from within an _Input, you get a crash.
This behavior was not present in official 3.1 builds, but it is present in current master mono builds.

I hit this a number of times in my game High Hat. I was also able to reproduce it in a sample project.

```
carter@beemo ~/Repro_MonoCrash> godot.x11.opt.tools.64.mono
Godot Engine v3.2.dev.mono.custom_build.ee58126cd - https://godotengine.org
OpenGL ES 2.0 Renderer: GeForce GTX 1070/PCIe/SSE2
Mono: Logfile is: /home/carter/.local/share/godot/mono/mono_logs/2019_06_15 14.19.00 (19749).txt
ERROR: mono_log_callback: Mono: FATAL ERROR, ABORTING! Logfile: /home/carter/.local/share/godot/mono/mono_logs/2019_06_15 14.19.00 (19749).txt

   At: modules/mono/mono_gd/gd_mono_log.cpp:75.

=================================================================
        Native Crash Reporting
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
/proc/self/maps:
00400000-00780000 r--p 00000000 103:05 1180805                           /home/carter/code/godot/bin/godot.x11.opt.tools.64.mono
00780000-02dfd000 r-xp 00380000 103:05 1180805                           /home/carter/code/godot/bin/godot.x11.opt.tools.64.mono
02dfd000-0405f000 r--p 029fd000 103:05 1180805                           /home/carter/code/godot/bin/godot.x11.opt.tools.64.mono
0405f000-04127000 r--p 03c5e000 103:05 1180805                           /home/carter/code/godot/bin/godot.x11.opt.tools.64.mono
04127000-0413f000 rw-p 03d26000 103:05 1180805                           /home/carter/code/godot/bin/godot.x11.opt.tools.64.mono
0413f000-04157000 rw-p 00000000 00:00 0 
04394000-0835a000 rw-p 00000000 00:00 0                                  [heap]
40731000-408c1000 rwxp 00000000 00:00 0 
40be1000-40bf1000 rwxp 00000000 00:00 0 
40bfa000-40cac000 rw-p 00000000 00:00 0 
4108c000-4109c000 rwxp 00000000 00:00 0 
41316000-41326000 rwxp 00000000 00:00 0 
41837000-41839000 r-xs 00000000 00:2c 726867                             /tmp/.glEE5j7S (deleted)
41c28000-41c38000 rwxp 00000000 00:00 0 
7fc467fff000-7fc46c000000 rw-p 00000000 00:00 0 
7fc46c000000-7fc46c021000 rw-p 00000000 00:00 0 
7fc46c021000-7fc470000000 ---p 00000000 00:00 0 
7fc474000000-7fc474021000 rw-p 00000000 00:00 0 
7fc474021000-7fc478000000 ---p 00000000 00:00 0 
7fc478000000-7fc478021000 rw-p 00000000 00:00 0 
7fc478021000-7fc47c000000 ---p 00000000 00:00 0 
7fc47c000000-7fc47c021000 rw-p 00000000 00:00 0 
7fc47c021000-7fc480000000 ---p 00000000 00:00 0 
7fc4831ff000-7fc4833ff000 rw-s 00000000 00:06 18956                      /dev/nvidiactl
7fc4833ff000-7fc4837ff000 rw-s 00000000 00:06 18956                      /dev/nvidiactl

=================================================================
        Basic Fault Adddress Reporting
=================================================================
Memory around native instruction pointer (0x7fc4a700282f):0x7fc4a700281f  d2 4c 89 ce bf 02 00 00 00 b8 0e 00 00 00 0f 05  .L..............
0x7fc4a700282f  48 8b 8c 24 08 01 00 00 64 48 33 0c 25 28 00 00  H..$....dH3.%(..
0x7fc4a700283f  00 44 89 c0 75 19 48 81 c4 10 01 00 00 5b c3 66  .D..u.H......[.f
0x7fc4a700284f  90 48 8b 15 e9 75 18 00 f7 d8 64 89 02 eb ba 67  .H...u....d....g

=================================================================
        Native stacktrace:
=================================================================
        0x7fc4a75cd49a - /usr/lib/libmonosgen-2.0.so.1 : (null)
        0x7fc4a7562fce - /usr/lib/libmonosgen-2.0.so.1 : (null)
        0x7fc4a792f4d0 - /usr/lib/libpthread.so.0 : (null)
        0x7fc4a700282f - /usr/lib/libc.so.6 : gsignal
        0x7fc4a6fed672 - /usr/lib/libc.so.6 : abort
        0x2b63c16 - godot.x11.opt.tools.64.mono : (null)
        0x7fc4a77b9e2c - /usr/lib/libmonosgen-2.0.so.1 : (null)
        0x7fc4a77ba253 - /usr/lib/libmonosgen-2.0.so.1 : monoeg_g_logv
        0x7fc4a77ba310 - /usr/lib/libmonosgen-2.0.so.1 : monoeg_g_log
        0x7fc4a77b11a5 - /usr/lib/libmonosgen-2.0.so.1 : (null)
        0x7fc4a77b2697 - /usr/lib/libmonosgen-2.0.so.1 : (null)
        0x7fc4a77b2715 - /usr/lib/libmonosgen-2.0.so.1 : mono_threads_enter_gc_safe_region_unbalanced
        0x408bef0b - Unknown

=================================================================
        Telemetry Dumper:
=================================================================
Pkilling 0x7fc4a4263700 from 0x7fc4a5adbdc0
Pkilling 0x7fc49df58700 from 0x7fc4a5adbdc0
Entering thread summarizer pause from 0x7fc4a5adbdc0
Finished thread summarizer pause from 0x7fc4a5adbdc0.
debugger-agent: Unable to listen on 78

Waiting for dumping threads to resume

Debug info from gdb:


=================================================================
        External Debugger Dump:
=================================================================
[New LWP 19750]
[New LWP 19753]
[New LWP 19754]
[New LWP 19755]
[New LWP 19756]
[New LWP 19757]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
0x00007fc4a792ee52 in waitpid () from /usr/lib/libpthread.so.0
  Id   Target Id                                           Frame 
* 1    Thread 0x7fc4a5adbdc0 (LWP 19749) "godot.x11.opt.t" 0x00007fc4a792ee52 in waitpid () from /usr/lib/libpthread.so.0
  2    Thread 0x7fc4a83f8700 (LWP 19750) "godot.x11.opt.t" 0x00007fc4a792d506 in do_futex_wait.constprop () from /usr/lib/libpthread.so.0
  3    Thread 0x7fc4a4a0c700 (LWP 19753) "godot.x11.opt.t" 0x00007fc4a792d506 in do_futex_wait.constprop () from /usr/lib/libpthread.so.0
  4    Thread 0x7fc4a43c9700 (LWP 19754) "godot.x11.opt.t" 0x00007fc4a792e960 in nanosleep () from /usr/lib/libpthread.so.0
  5    Thread 0x7fc4a4388700 (LWP 19755) "godot.x11.opt.t" 0x00007fc4a7092908 in nanosleep () from /usr/lib/libc.so.6
  6    Thread 0x7fc49d7ff700 (LWP 19756) "SGen worker"     0x00007fc4a792abac in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
  7    Thread 0x7fc4a4263700 (LWP 19757) "Finalizer"       0x00007fc4a792d506 in do_futex_wait.constprop () from /usr/lib/libpthread.so.0

Thread 7 (Thread 0x7fc4a4263700 (LWP 19757)):
#0  0x00007fc4a792d506 in do_futex_wait.constprop () from /usr/lib/libpthread.so.0
#1  0x00007fc4a792d608 in __new_sem_wait_slow.constprop.0 () from /usr/lib/libpthread.so.0
#2  0x00007fc4a7742b0a in ?? () from /usr/lib/libmonosgen-2.0.so.1
#3  0x00007fc4a76ee93c in ?? () from /usr/lib/libmonosgen-2.0.so.1
#4  0x00007fc4a7924a92 in start_thread () from /usr/lib/libpthread.so.0
#5  0x00007fc4a70c5cd3 in clone () from /usr/lib/libc.so.6

Thread 6 (Thread 0x7fc49d7ff700 (LWP 19756)):
#0  0x00007fc4a792abac in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
#1  0x00007fc4a7794144 in ?? () from /usr/lib/libmonosgen-2.0.so.1
#2  0x00007fc4a7924a92 in start_thread () from /usr/lib/libpthread.so.0
#3  0x00007fc4a70c5cd3 in clone () from /usr/lib/libc.so.6

Thread 5 (Thread 0x7fc4a4388700 (LWP 19755)):
#0  0x00007fc4a7092908 in nanosleep () from /usr/lib/libc.so.6
#1  0x00007fc4a70be1b8 in usleep () from /usr/lib/libc.so.6
#2  0x0000000002cd8297 in JoypadLinux::monitor_joypads() ()
#3  0x0000000002534de5 in ThreadPosix::thread_callback(void*) ()
#4  0x00007fc4a7924a92 in start_thread () from /usr/lib/libpthread.so.0
#5  0x00007fc4a70c5cd3 in clone () from /usr/lib/libc.so.6

Thread 4 (Thread 0x7fc4a43c9700 (LWP 19754)):
#0  0x00007fc4a792e960 in nanosleep () from /usr/lib/libpthread.so.0
#1  0x0000000000bbd8eb in OS_Unix::delay_usec(unsigned int) const [clone .constprop.12479] ()
#2  0x0000000002597bf4 in AudioDriverPulseAudio::thread_func(void*) ()
#3  0x0000000002534de5 in ThreadPosix::thread_callback(void*) ()
#4  0x00007fc4a7924a92 in start_thread () from /usr/lib/libpthread.so.0
#5  0x00007fc4a70c5cd3 in clone () from /usr/lib/libc.so.6

Thread 3 (Thread 0x7fc4a4a0c700 (LWP 19753)):
#0  0x00007fc4a792d506 in do_futex_wait.constprop () from /usr/lib/libpthread.so.0
#1  0x00007fc4a792d608 in __new_sem_wait_slow.constprop.0 () from /usr/lib/libpthread.so.0
#2  0x0000000002482dbd in SemaphorePosix::wait() [clone .part.0] ()
#3  0x000000000120a2b3 in VisualServerScene::_gi_probe_bake_thread() ()
#4  0x0000000002534de5 in ThreadPosix::thread_callback(void*) ()
#5  0x00007fc4a7924a92 in start_thread () from /usr/lib/libpthread.so.0
#6  0x00007fc4a70c5cd3 in clone () from /usr/lib/libc.so.6

Thread 2 (Thread 0x7fc4a83f8700 (LWP 19750)):
#0  0x00007fc4a792d506 in do_futex_wait.constprop () from /usr/lib/libpthread.so.0
#1  0x00007fc4a792d608 in __new_sem_wait_slow.constprop.0 () from /usr/lib/libpthread.so.0
#2  0x0000000002482dbd in SemaphorePosix::wait() [clone .part.0] ()
#3  0x0000000000d10d84 in _IP_ResolverPrivate::_thread_function(void*) ()
#4  0x0000000002534de5 in ThreadPosix::thread_callback(void*) ()
#5  0x00007fc4a7924a92 in start_thread () from /usr/lib/libpthread.so.0
#6  0x00007fc4a70c5cd3 in clone () from /usr/lib/libc.so.6

Thread 1 (Thread 0x7fc4a5adbdc0 (LWP 19749)):
#0  0x00007fc4a792ee52 in waitpid () from /usr/lib/libpthread.so.0
#1  0x00007fc4a75cd71a in ?? () from /usr/lib/libmonosgen-2.0.so.1
#2  0x00007fc4a7562fce in ?? () from /usr/lib/libmonosgen-2.0.so.1
#3  <signal handler called>
#4  0x00007fc4a700282f in raise () from /usr/lib/libc.so.6
#5  0x00007fc4a6fed672 in abort () from /usr/lib/libc.so.6
#6  0x0000000002b63c16 in mono_log_callback(char const*, char const*, char const*, int, void*) ()
#7  0x00007fc4a77b9e2c in ?? () from /usr/lib/libmonosgen-2.0.so.1
#8  0x00007fc4a77ba253 in monoeg_g_logv () from /usr/lib/libmonosgen-2.0.so.1
#9  0x00007fc4a77ba310 in monoeg_g_log () from /usr/lib/libmonosgen-2.0.so.1
#10 0x00007fc4a77b11a5 in ?? () from /usr/lib/libmonosgen-2.0.so.1
#11 0x00007fc4a77b2697 in ?? () from /usr/lib/libmonosgen-2.0.so.1
#12 0x00007fc4a77b2715 in mono_threads_enter_gc_safe_region_unbalanced () from /usr/lib/libmonosgen-2.0.so.1
#13 0x00000000408bef0b in ?? ()
#14 0x00007fc49d8bfc70 in ?? ()
#15 0x00007fc49d8bfc20 in ?? ()
#16 0x0000000000000000 in ?? ()
[Inferior 1 (process 19749) detached]

=================================================================
        Managed Stacktrace:
=================================================================
          at <unknown> <0xffffffff>
          at Godot.GD:godot_icall_GD_print <0x000ba>
          at Godot.GD:Print <0x001af>
          at Root:DoSomething <0x00107>
          at <Module>:runtime_invoke_void__this___int <0x000db>
          at <unknown> <0xffffffff>
          at Godot.NativeCalls:godot_icall_2_552 <0x000f3>
          at Godot.Node:Rpc <0x000cb>
          at Root:_Input <0x00233>
          at <Module>:runtime_invoke_void__this___object <0x000d8>
=================================================================
fish: “godot.x11.opt.tools.64.mono” terminated by signal SIGABRT (Abort)
```

**Steps to reproduce:**
* Create an _Input() function
* Make an RPC call from within the _Input function
* Call a method in the RPC call that makes a Godot.NativeCalls:godot_icall_XXX (ex: GD.Print)

**Minimal reproduction project:**
[Repro_MonoCrash.zip](https://github.com/godotengine/godot/files/3293562/Repro_MonoCrash.zip)