GNOME Bugzilla – Bug 767877
Using closures + async causes sefault
Last modified: 2018-05-22 15:36:49 UTC
Created attachment 330090 [details] C code generated by valac This code with vala 0.30 compiles but crashes. I use mac os x, GLib 2.46.2. public class Test : Object { public void test_sync(string data) { Idle.add(() => { do_something(data); return false; }); } public async void test_async(string data) { Idle.add(() => { do_something(data); return false; }); Idle.add(test_async.callback); } private void do_something(string data) { stdout.printf("%s\n", data); } } public static int main(string[] argv) { var instance = new Test(); instance.test_sync("test sync"); instance.test_async.begin("test async", (obj, res) => { instance.test_async.end(res); }); new MainLoop().run(); return 0; } Compile with: valac --pkg gio-2.0 async-closure.vala Output: $ ./async-closure test sync test async (process:88038): GLib-GObject-CRITICAL **: g_object_ref: assertion 'G_IS_OBJECT (object)' failed (process:88038): GLib-GIO-CRITICAL **: g_simple_async_result_complete_in_idle: assertion 'G_IS_SIMPLE_ASYNC_RESULT (simple)' failed (process:88038): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed ** (process:88038): CRITICAL **: test_do_something: assertion 'self != NULL' failed GLib (gthread-posix.c): Unexpected error from C library during 'pthread_setspecific': Invalid argument. Aborting. Abort trap: 6 backtrace * thread #1: tid = 0x0000, 0x00007fff8b52ff06 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGSTOP * frame #0: 0x00007fff8b52ff06 libsystem_kernel.dylib`__pthread_kill + 10 frame #1: 0x00007fff9ba1c4ec libsystem_pthread.dylib`pthread_kill + 90 frame #2: 0x00007fff94cae6e7 libsystem_c.dylib`abort + 129 frame #3: 0x00007fff9a582041 libsystem_malloc.dylib`free + 425 frame #4: 0x000000010220dc1b async-closure`block2_data_unref + 75 frame #5: 0x00000001024d9213 libglib-2.0.0.dylib`g_source_callback_unref + 35 frame #6: 0x00000001024d30b1 libglib-2.0.0.dylib`g_source_destroy_internal + 97 frame #7: 0x00000001024d6a33 libglib-2.0.0.dylib`g_main_context_dispatch + 435 frame #8: 0x00000001024d6cf4 libglib-2.0.0.dylib`g_main_context_iterate + 420 frame #9: 0x00000001024d701f libglib-2.0.0.dylib`g_main_loop_run + 223 frame #10: 0x000000010220d918 async-closure`_vala_main + 200 frame #11: 0x000000010220da62 async-closure`main + 34 frame #12: 0x00007fff9b8465ad libdyld.dylib`start + 1 frame #13: 0x00007fff9b8465ad libdyld.dylib`start + 1
The same with 0.32.0
I think that this is not a bug. your code is buggy. You cannot do public async void test_async(string data) { Idle.add(() => { do_something(data); return false; }); Idle.add(test_async.callback); } you cannot call test_async.callback without yeld it. Calling test_async.callback means call again test_async starting from the yield. If there is no yield you call again the same function starting from beginning and you enter in infinite loop. but I'm working on another fix so support async call of not really async function that teorically solve also this.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/544.