After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 773789 - rhythmbox crashed with SIGSEGV in grl_util_fetch_done ( grl-lua-library.c )
rhythmbox crashed with SIGSEGV in grl_util_fetch_done ( grl-lua-library.c )
Status: RESOLVED OBSOLETE
Product: grilo
Classification: Other
Component: plugins
0.3.x
Other Linux
: Normal normal
: ---
Assigned To: grilo-maint
grilo-maint
Depends on:
Blocks:
 
 
Reported: 2016-11-01 19:59 UTC by gnome.vrb
Modified: 2018-09-24 09:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
lua-factory: Improve error handling in fetch callback (2.04 KB, patch)
2016-11-29 21:21 UTC, Victor Toso
none Details | Review
lua-factory: Fix double free on grl_util_fetch_done (1.12 KB, patch)
2016-11-29 21:22 UTC, Victor Toso
none Details | Review
lua-factory: Fix possible crash when fetch ops are cancelled (2.12 KB, patch)
2016-11-30 00:20 UTC, Bastien Nocera
committed Details | Review
lua-factory: Fix memory leak (948 bytes, patch)
2016-11-30 00:20 UTC, Bastien Nocera
committed Details | Review
Grilo debug logs with assertion failures (43.17 KB, text/plain)
2016-12-20 06:39 UTC, gnome.vrb
  Details

Description gnome.vrb 2016-11-01 19:59:26 UTC
I don't have the steps to reproduce this issue. Hence, I am pasting a complete backtrace to see if that might help.

(gdb) backtrace full
  • #0 __GI_raise
    at ../sysdeps/unix/sysv/linux/raise.c line 58
  • #1 __GI_abort
    at abort.c line 89
  • #2 __libc_message
    at ../sysdeps/posix/libc_fatal.c line 175
  • #3 malloc_printerr
  • #4 _int_free
    at malloc.c line 3902
  • #5 grl_util_fetch_done
    at grl-lua-library.c line 551
  • #6 g_simple_async_result_complete
    at ././gio/gsimpleasyncresult.c line 801
  • #7 reply_cb
    at grl-net-wc.c line 648
  • #8 g_task_return_now
    at ././gio/gtask.c line 1121
  • #9 g_task_return
    at ././gio/gtask.c line 1179
  • #10 http_input_stream_ready_cb
    at soup-request-http.c line 126
  • #11 g_task_return_now
    at ././gio/gtask.c line 1121
  • #12 g_task_return
    at ././gio/gtask.c line 1179
  • #13 async_send_request_return_result
    at soup-session.c line 3877
  • #14 _g_closure_invoke_va
    at ././gobject/gclosure.c line 867
  • #15 g_signal_emit_valist
    at ././gobject/gsignal.c line 3300
  • #16 g_signal_emit
    at ././gobject/gsignal.c line 3447
  • #17 soup_message_finished
    at soup-message.c line 1169
  • #18 soup_session_process_queue_item
    at soup-session.c line 2029
  • #19 async_run_queue
    at soup-session.c line 2077
  • #20 connect_async_complete
    at soup-session.c line 1784
  • #21 g_task_return_now
    at ././gio/gtask.c line 1121
  • #22 g_task_return
    at ././gio/gtask.c line 1179
  • #23 socket_connect_finished
    at soup-connection.c line 334
  • #24 socket_connect_complete
    at soup-connection.c line 359
  • #25 g_task_return_now
    at ././gio/gtask.c line 1121
  • #26 g_task_return
    at ././gio/gtask.c line 1179
  • #27 async_connected
    at soup-socket.c line 923
  • #28 g_task_return_now
    at ././gio/gtask.c line 1121
  • #29 g_task_return
    at ././gio/gtask.c line 1179
  • #30 g_task_return_error_if_cancelled
    at ././gio/gtask.c line 1806
  • #31 g_socket_client_connected_callback
    at ././gio/gsocketclient.c line 1493
  • #32 g_task_return_now
    at ././gio/gtask.c line 1121
  • #33 g_task_return
    at ././gio/gtask.c line 1179
  • #34 g_socket_connection_connect_callback
    at ././gio/gsocketconnection.c line 237
  • #35 socket_source_dispatch
    at ././gio/gsocket.c line 3543
  • #36 g_main_context_dispatch
    at ././glib/gmain.c line 3203
  • #37 g_main_context_dispatch
    at ././glib/gmain.c line 3856
  • #38 g_main_context_iterate
    at ././glib/gmain.c line 3929
  • #39 g_main_context_iteration
    at ././glib/gmain.c line 3990
  • #40 g_application_run
    at ././gio/gapplication.c line 2405
  • #41 rb_application_run
    at rb-application.c line 667
  • #42 main
    at main.c line 88

Comment 1 gnome.vrb 2016-11-01 20:02:58 UTC
root@unstable:~# dpkg -l | grep -i grilo | awk '{ print $2, $3 }'
gir1.2-grilo-0.3:amd64 0.3.2-2
grilo-plugins-0.3:amd64 0.3.3-1
grilo-plugins-0.3-dbgsym:amd64 0.3.3-1
libgrilo-0.3-0:amd64 0.3.2-2
libgrilo-0.3-0-dbgsym:amd64 0.3.2-2
libgrilo-0.3-bin 0.3.2-2
libgrilo-0.3-bin-dbgsym 0.3.2-2
libgrilo-0.3-dev:amd64 0.3.2-2
libgrilo-0.3-doc 0.3.2-2

root@unstable:~# uname -a
Linux unstable 4.7.0-1-amd64 #1 SMP Debian 4.7.8-1 (2016-10-19) x86_64 GNU/Linux
Comment 2 gnome.vrb 2016-11-29 14:02:12 UTC
Got another crash. I've saved the core file + app for information if needed.

  • #0 __GI_raise
    at ../sysdeps/unix/sysv/linux/raise.c line 58
  • #1 __GI_abort
    at abort.c line 89
  • #2 __libc_message
    at ../sysdeps/posix/libc_fatal.c line 175
  • #3 malloc_printerr
  • #4 _int_free
    at malloc.c line 3902
  • #5 grl_util_fetch_done
    at grl-lua-library.c line 551
  • #6 g_simple_async_result_complete
    at ././gio/gsimpleasyncresult.c line 801
  • #7 reply_cb
    at grl-net-wc.c line 651
  • #8 g_task_return_now
    at ././gio/gtask.c line 1121
  • #9 g_task_return
    at ././gio/gtask.c line 1179
  • #10 http_input_stream_ready_cb
    at soup-request-http.c line 124
  • #11 g_task_return_now
    at ././gio/gtask.c line 1121
  • #12 g_task_return
    at ././gio/gtask.c line 1179
  • #13 async_send_request_return_result
    at soup-session.c line 3886
  • #14 _g_closure_invoke_va
    at ././gobject/gclosure.c line 867
  • #15 g_signal_emit_valist
    at ././gobject/gsignal.c line 3300
  • #16 g_signal_emit
    at ././gobject/gsignal.c line 3447
  • #17 soup_message_finished
    at soup-message.c line 1169
  • #18 soup_session_process_queue_item
    at soup-session.c line 2029
  • #19 try_run_until_read
    at soup-session.c line 4040
  • #20 read_ready_cb
    at soup-session.c line 4011
  • #21 g_main_context_dispatch
    at ././glib/gmain.c line 3203
  • #22 g_main_context_dispatch
    at ././glib/gmain.c line 3856
  • #23 g_main_context_iterate
    at ././glib/gmain.c line 3929
  • #24 g_main_context_iteration
    at ././glib/gmain.c line 3990
  • #25 g_application_run
    at ././gio/gapplication.c line 2405
  • #26 rb_application_run
    at rb-application.c line 651
  • #27 main
    at main.c line 88

Comment 3 Victor Toso 2016-11-29 17:44:09 UTC
I think I understood the issue.

When the source fetches multiple urls at once but eventually get cancelled:
1) first time on grl_util_fetch_done(), release each fo->results[i] and then release fo->results
2) second time on grl_util_fetch_done(), try to free fo->results[i] and crash as result was freed before

Cooking a patch.
Comment 4 Victor Toso 2016-11-29 21:21:57 UTC
Created attachment 340996 [details] [review]
lua-factory: Improve error handling in fetch callback

When we did not fetch all requested urls, we want to go to
free_fetch_op in order to clean FetchOperation resources;

After successfully providing the fetched data to the Lua Source or in
case of G_IO_ERROR_CANCELLED we want to terminate the FetchOperation
with all shared resources.

This also fix a leak of GCancellable that was not being properly
unref'ed
Comment 5 Victor Toso 2016-11-29 21:22:06 UTC
Created attachment 340997 [details] [review]
lua-factory: Fix double free on grl_util_fetch_done

In case we are canceling a fetch operation with multiple urls, we
should avoid freeing fo->results and its elements more then once.
Comment 6 Victor Toso 2016-11-29 21:27:40 UTC
Easy to reproduce with grilo-test-ui-0.3, the trick is being fast to trigger the cancelation:

1-) launch grilo-test-ui-0.3
2-) click once to select Radio France
3-) put the mouse in the Back button
4-) Press Enter to enter in Radio France
5-) Click in the back button as fast as you can.

It will trigger the cancelation of multiple urls fetch, causing the crash.
Comment 7 Bastien Nocera 2016-11-30 00:20:22 UTC
Created attachment 341006 [details] [review]
lua-factory: Fix possible crash when fetch ops are cancelled

When an operation was cancelled, we would go to free our operation data
straight away, including struct members shared with other operations.

As those could be on-going, and we know that the operations data members
that are private to our operation are valid, go check whether we are the
last operation, and only free the shared resources in that case.
Comment 8 Bastien Nocera 2016-11-30 00:20:28 UTC
Created attachment 341007 [details] [review]
lua-factory: Fix memory leak

The cancellable referenced in each fetch operation's data was not
unreferenced except the one in the last fetch in the sequence.
Comment 9 Bastien Nocera 2016-11-30 00:23:41 UTC
I prefer my patches.

The only thing I'm unsure is whether we should touch the lua _State when we're cancelled, as we don't hold a reference to it, and the lua-factory might already have been destroyed already.

Or maybe it's still alive because it's through its userdata cleanup that we're getting cancelled.

Ideas, Victor?
Comment 10 Victor Toso 2016-11-30 07:53:50 UTC
(In reply to Bastien Nocera from comment #9)
> I prefer my patches.

:)

I'm fine with either but I would have appreciated a review on my patch if you saw any issue there so I can make it better next time.

> The only thing I'm unsure is whether we should touch the lua_State when
> we're cancelled, as we don't hold a reference to it, and the lua-factory
> might already have been destroyed already.
> 
> Or maybe it's still alive because it's through its userdata cleanup that
> we're getting cancelled.

No, I think you are right and it could happen that grl_util_fetch_done() being called when LuaFactory plugin has been destroyed.

> 
> Ideas, Victor?

No sure. We might need to start using GWeakNotify to verify this kind of situation and perhaps a helper functions in grl-lua-library-operations to check if operation is still valid.

Although I would say that GCancellable should used in Grilo itself so plugins don't need to workaround it.

Cheers

PS: Ack both your patches
Comment 11 gnome.vrb 2016-12-20 06:37:06 UTC
Don't see the crash anymore with attachment 341006 [details] [review] and attachment 341007 [details] [review]. But, seeing a lot of assertion errors:

(rhythmbox:19687): Grilo-CRITICAL **: grl_source_get_id: assertion 'GRL_IS_SOURCE (source)' failed
(rhythmbox:19687): Grilo-DEBUG: [lua-library-operations] grl-lua-library-operations.c:899: grl_lua_operations_set_source_state | (null) (op-id: 0) state: finalized

(rhythmbox:19687): Grilo-CRITICAL **: grl_source_get_id: assertion 'GRL_IS_SOURCE (source)' failed
(rhythmbox:19687): Grilo-DEBUG: [lua-library-operations] grl-lua-library-operations.c:588: watchdog_operation_gc | (null) (op-id: 0) current state is: finalized (num-async-op: 32610)

(rhythmbox:19687): Grilo-CRITICAL **: grl_source_get_id: assertion 'GRL_IS_SOURCE (source)' failed

(rhythmbox:19687): Grilo-WARNING **: [lua-library-operations] grl-lua-library-operations.c:614: Source '(null)' is broken, as the finishing callback was called while 32610 operations are still ongoing
Comment 12 gnome.vrb 2016-12-20 06:39:18 UTC
Created attachment 342246 [details]
Grilo debug logs with assertion failures

Assertion failures don't happen every time though. Seems to be dependent on the timing of the cancellations.
Comment 13 gnome.vrb 2016-12-20 18:59:05 UTC
Got a randomly reproducible crash with [ 341006, 341007 ]

(gdb) bt
  • #0 grl_source_get_id
    at grl-source.c line 2987
  • #1 grl_lua_operations_pcall
    at grl-lua-library-operations.c line 850
  • #2 grl_util_fetch_done
    at grl-lua-library.c line 544
  • #3 g_simple_async_result_complete
    at ././gio/gsimpleasyncresult.c line 801
  • #4 read_async_cb
    at grl-net-wc.c line 623
  • #5 async_ready_callback_wrapper
    at ././gio/ginputstream.c line 532
  • #6 g_task_return_now
    at ././gio/gtask.c line 1121
  • #7 complete_in_idle_cb
    at ././gio/gtask.c line 1135
  • #8 g_main_context_dispatch
    at ././glib/gmain.c line 3203
  • #9 g_main_context_dispatch
    at ././glib/gmain.c line 3856
  • #10 g_main_context_iterate
    at ././glib/gmain.c line 3929
  • #11 g_main_context_iteration
    at ././glib/gmain.c line 3990
  • #12 g_application_run
    at ././gio/gapplication.c line 2405
  • #13 rb_application_run
    at rb-application.c line 667
  • #14 main
    at main.c line 88

Comment 14 gnome.vrb 2016-12-20 19:02:12 UTC
Assertion failures in different places:

(rhythmbox:12003): libsoup-CRITICAL **: async_send_request_return_result: assertion 'item->task != NULL' failed
(rhythmbox:12003): Grilo-DEBUG: [lua-library] grl-lua-library.c:486: fetch operation was cancelled

(rhythmbox:12003): libsoup-CRITICAL **: async_send_request_return_result: assertion 'item->task != NULL' failed
(rhythmbox:12003): Grilo-DEBUG: [lua-library] grl-lua-library.c:486: fetch operation was cancelled

(rhythmbox:12003): libsoup-CRITICAL **: async_send_request_return_result: assertion 'item->task != NULL' failed
Comment 15 gnome.vrb 2016-12-20 19:02:30 UTC
Assertion failures in different places:

(rhythmbox:12382): Grilo-CRITICAL **: grl_source_get_id: assertion 'GRL_IS_SOURCE (source)' failed
(rhythmbox:12382): Grilo-DEBUG: [lua-library-operations] grl-lua-library-operations.c:852: grl_lua_operations_pcall | (null) (op-id: 0)

(rhythmbox:12382): Grilo-CRITICAL **: grl_source_get_id: assertion 'GRL_IS_SOURCE (source)' failed
(rhythmbox:12382): Grilo-DEBUG: [lua-library-operations] grl-lua-library-operations.c:899: grl_lua_operations_set_source_state | (null) (op-id: 0) state: running

(rhythmbox:12382): Grilo-CRITICAL **: grl_source_get_id: assertion 'GRL_IS_SOURCE (source)' failed
(rhythmbox:12382): Grilo-DEBUG: [lua-library-operations] grl-lua-library-operations.c:277: priv_state_operations_create_source_state | (null) (op-id: 0)
Comment 16 Victor Toso 2017-02-14 11:41:25 UTC
Based on comment #11 and comment #12, these patches improves the issue.

Attachment 341006 [details] pushed as a051aa0 - lua-factory: Fix possible crash when fetch ops are cancelled
Attachment 341007 [details] pushed as 98ba622 - lua-factory: Fix memory leak

Keeping the bug open to address the criticals afterwards
Comment 17 GNOME Infrastructure Team 2018-09-24 09:50:35 UTC
-- 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/grilo/issues/105.