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 692451 - Anjuta crash when 'Refresh' after external file change
Anjuta crash when 'Refresh' after external file change
Status: RESOLVED FIXED
Product: anjuta
Classification: Applications
Component: plugins: editor: gtksourceview
3.6.x
Other Linux
: Normal major
: ---
Assigned To: Johannes Schmid
Anjuta maintainers
Depends on:
Blocks:
 
 
Reported: 2013-01-24 14:38 UTC by John
Modified: 2013-02-25 14:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
sourceview: move all construction of Sourceview into constructed (8.03 KB, patch)
2013-02-21 21:55 UTC, Carl-Anton Ingmarsson
committed Details | Review
sourceview: keep a separate reference to AnjutaShell in SourceviewIO (3.02 KB, patch)
2013-02-21 21:55 UTC, Carl-Anton Ingmarsson
reviewed Details | Review
sourceview: only cancel open operations when closing editor (4.80 KB, patch)
2013-02-21 21:55 UTC, Carl-Anton Ingmarsson
accepted-commit_now Details | Review
sourceview: add checks to SourceviewIO that the parent Sourceview is alive (2.45 KB, patch)
2013-02-21 21:55 UTC, Carl-Anton Ingmarsson
committed Details | Review
sourceview: don't take extra refs during open/save (2.70 KB, patch)
2013-02-21 21:55 UTC, Carl-Anton Ingmarsson
committed Details | Review
sourceview: keep a separate reference to AnjutaShell in SourceviewIO (3.02 KB, patch)
2013-02-23 11:16 UTC, Carl-Anton Ingmarsson
committed Details | Review
sourceview: only cancel open operations when closing editor (5.95 KB, patch)
2013-02-24 18:53 UTC, Carl-Anton Ingmarsson
committed Details | Review

Description John 2013-01-24 14:38:13 UTC
It took me a while to detect the mechanism behind this, but I'm fairly certain this is it:

- When modifying a project file externally (eg. using an editor, or glade2),
Anjuta displays the 'orange' bar warning about the change, and offering to
refresh the editor file.

- Infrequently, this causes Anjuta to crash, without saving the session, so
this caused quite a bit of reconfiguring each time.

The irregularity of the problem (say once each 10 times or so) had me confused,
but I'm quite certain this happens if an auto-save occurs while the file has
not been 'refreshed'.

I have been working without UPS for some days and had set the auto-save to
3 minutes. The crashes happened more frequently... Back on UPS, I'll switch
off the auto-save if it goes away.

John
Comment 1 Sébastien Granjoux 2013-01-24 18:49:14 UTC
Thanks for reporting this. 

> - Infrequently, this causes Anjuta to crash, without saving the session, so
> this caused quite a bit of reconfiguring each time.

The configuration is saved only when a session is closed (when you quit Anjuta or close the project). I'm agree that's it's quite annoying when you get a crash in Anjuta. I'm thinking that perhaps it would be nice to save them automatically from time to time or even after each change.


> The irregularity of the problem (say once each 10 times or so) had me confused,
> but I'm quite certain this happens if an auto-save occurs while the file has
> not been 'refreshed'.

I will check this. Which editor are you using? Scintilla or GtkSourceView.
Comment 2 John 2013-01-25 01:56:50 UTC
> I'm thinking that perhaps it would be nice to save them
automatically from time to time or even after each change.

That would be very helpful. Maybe a save after 1 or 2 minutes
of the last change?

> I will check this. Which editor are you using? Scintilla or GtkSourceView.

At the moment, GtkSourceView. I left Scintilla because of the
configuration problems. I still have to test your patch, but
the last weeks have been very difficult here...

I've been using Anjuta without the auto-backup for some 4 hours,
and have not had any crash, even with many 'refreshes'.

John
Comment 3 John 2013-01-25 14:14:51 UTC
> I've been using Anjuta without the auto-backup for some 4 hours,
  and have not had any crash, even with many 'refreshes'.

Well, today I had a crash again, now  with auto-save disabled. So
that wasn't the cause.

In fact, I just had two crashes:

- the first was on the classic 'Refresh' button click

- for the first time, I had a crash when clicking on 'save' in the
'save' dialog which appears when closing a tab of a modified file.
This is the first time, but I rarely enter this situation, as most
files have been saved before (either because I compiled the project,
or because of an auto-save)

John
Comment 4 John 2013-01-25 14:21:06 UTC
I just forced the 'save' modified file dialog scenario again, and had
another crash (see below). This crash seems to be GtkSourceview related.
Seems strange to do an autodetect_language on saving a file?

Program received signal SIGSEGV, Segmentation fault.
sourceview_io_get_mime_type (sio=0x0) at sourceview-io.c:516
516		if (!sio->file)

Backtrace:

  • #0 sourceview_io_get_mime_type
    at sourceview-io.c line 516
  • #1 autodetect_language
    at sourceview.c line 2118
  • #2 on_save_finish
    at sourceview.c line 785
  • #3 g_closure_invoke
    at gclosure.c line 777
  • #4 signal_emit_unlocked_R
    at gsignal.c line 3551
  • #5 g_signal_emit_valist
    at gsignal.c line 3300
  • #6 g_signal_emit_by_name
    at gsignal.c line 3393
  • #7 on_save_finished
    at sourceview-io.c line 258
  • #8 g_simple_async_result_complete
    at gsimpleasyncresult.c line 775
  • #9 replace_contents_close_callback
    at gfile.c line 6986
  • #10 async_ready_close_callback_wrapper
    at goutputstream.c line 685
  • #11 g_simple_async_result_complete
    at gsimpleasyncresult.c line 775
  • #12 complete_in_idle_cb_for_thread
    at gsimpleasyncresult.c line 843
  • #13 g_main_dispatch
    at gmain.c line 2715
  • #14 g_main_context_dispatch
    at gmain.c line 3219
  • #15 g_main_context_iterate
    at gmain.c line 3290
  • #16 g_main_context_iteration
    at gmain.c line 3351
  • #17 g_application_run
    at gapplication.c line 1624
  • #18 main
    at main.c line 211

Comment 5 John 2013-01-25 15:08:35 UTC
Well, it seems both crash types are GtkSourceView-related - maybe this bug should be directed there...

Here is the gdb info for the crash on 'Refresh':

Program received signal SIGSEGV, Segmentation fault.
_gtk_source_buffer_source_mark_next (buffer=0x1ec0960, mark=mark@entry=0x2bd2b40, category=category@entry=0x0)
    at gtksourcebuffer.c:1865
1865		while (mark != g_array_index (buffer->priv->source_marks, GtkSourceMark *, idx))

Backtrace:

  • #0 _gtk_source_buffer_source_mark_next
    at gtksourcebuffer.c line 1865
  • #1 gtk_source_mark_next
    at gtksourcemark.c line 228
  • #2 sourceview_reload_save_markers
    at sourceview.c line 482
  • #3 on_reload_dialog_response
    at sourceview.c line 520
  • #4 g_cclosure_marshal_VOID__INTv
    at gmarshal.c line 410
  • #5 _g_closure_invoke_va
    at gclosure.c line 840
  • #6 g_signal_emit_valist
    at gsignal.c line 3211
  • #7 g_signal_emit
    at gsignal.c line 3356
  • #8 _g_closure_invoke_va
    at gclosure.c line 840
  • #9 g_signal_emit_valist
    at gsignal.c line 3211
  • #10 g_signal_emit
    at gsignal.c line 3356
  • #11 gtk_real_button_released
    at gtkbutton.c line 1967
  • #12 _g_closure_invoke_va
    at gclosure.c line 840
  • #13 g_signal_emit_valist
    at gsignal.c line 3211
  • #14 g_signal_emit
    at gsignal.c line 3356
  • #15 gtk_button_button_release
    at gtkbutton.c line 1802
  • #16 gtk_button_button_release
    at gtkbutton.c line 1794
  • #17 _gtk_marshal_BOOLEAN__BOXEDv
    at gtkmarshalers.c line 130
  • #18 _g_closure_invoke_va
    at gclosure.c line 840
  • #19 g_signal_emit_valist
    at gsignal.c line 3211
  • #20 g_signal_emit
    at gsignal.c line 3356
  • #21 gtk_widget_event_internal
    at gtkwidget.c line 6301
  • #22 gtk_widget_event
    at gtkwidget.c line 5958
  • #23 propagate_event_up
    at gtkmain.c line 2397
  • #24 propagate_event
    at gtkmain.c line 2497
  • #25 gtk_main_do_event
    at gtkmain.c line 1720
  • #26 gdk_event_source_dispatch
    at gdkeventsource.c line 358
  • #27 g_main_dispatch
    at gmain.c line 2715
  • #28 g_main_context_dispatch
    at gmain.c line 3219
  • #29 g_main_context_iterate
    at gmain.c line 3290
  • #30 g_main_context_iteration
    at gmain.c line 3351
  • #31 g_application_run
    at gapplication.c line 1624
  • #32 main
    at main.c line 211

Comment 6 Sébastien Granjoux 2013-01-27 14:39:02 UTC
I have tried with GtkSourceView but I haven't get any crash by using refresh.

I'm not sure it's linked to the automatic refresh because only modified files are saved. When you modify a file outside Anjuta, I expect that you don't change it in Anjuta too, so it shouldn't be a problem.

I still get a critical warning when refreshing a file for the second time using GtkSourceView. I don't get it with Scintilla.
Comment 7 Johannes Schmid 2013-01-27 15:22:59 UTC
Can you post the warning you get on second refresh?

Carl-Anton fixed a couple of problems in the GtkSourceView I/O code in master so he might also have fixed he crash because it looks like a memory corruption to me.
Comment 8 John 2013-01-27 16:07:52 UTC
As I commented before - I don't think anymore it is related to the 
refresh per se, but could rather be related to the file saving/loading in general:

> - for the first time, I had a crash when clicking on 'save' in the
> 'save' dialog which appears when closing a tab of a modified file.
> This is the first time, but I rarely enter this situation, as most
> files have been saved before (either because I compiled the project,
> or because of an auto-save)

Consistently (=every time) Anjuta segfaults when I do:

1) change the contents of a file in the editor
2) Immediately try to close the tab (using the 'x' on it)
3) I get the 'want to save' dialog and click Save.

---------------
(anjuta:982): GLib-GObject-WARNING **: invalid uninstantiatable type `(null)' in cast to `GtkTextBuffer'

(anjuta:982): Gtk-CRITICAL **: gtk_text_buffer_set_modified: assertion `GTK_IS_TEXT_BUFFER (buffer)' failed

Program received signal SIGSEGV, Segmentation fault.
sourceview_io_get_mime_type (sio=0x0) at sourceview-io.c:516
516		if (!sio->file)
---------------

... which gives the impression the GtkTextBuffer was already destroyed.

Note that 'manual saves' like Ctrl-S, (menu Save), or saves caused by
compilation _never_ caused a crash - but then they don't close the
editor.
Comment 9 Sébastien Granjoux 2013-01-27 20:08:18 UTC
I get the following warning: GtkSourceView-CRITICAL **: modified_changed_handler: assertion `action != NULL' failed

  • #0 g_logv
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #1 g_log
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #2 g_closure_invoke
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #3 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #4 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #5 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #6 g_closure_invoke
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #7 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #8 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #9 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #10 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #11 ??
    from /usr/lib/x86_64-linux-gnu/libgtksourceview-3.0.so.0
  • #12 g_closure_invoke
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #13 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #14 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #15 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #16 gtk_text_buffer_set_text
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #17 ifile_open
    at ../../../plugins/sourceview/sourceview.c line 999
  • #18 ianjuta_file_open
    at ../../../libanjuta/interfaces/ianjuta-file.c line 83
  • #19 on_reload_dialog_response
    at ../../../plugins/sourceview/sourceview.c line 550
  • #20 g_cclosure_marshal_VOID(int0_t, void)
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #21 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #22 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #23 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #24 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #25 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #26 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #27 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #28 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #29 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #30 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #31 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #32 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #33 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #34 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #35 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #36 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #37 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #38 gtk_main_do_event
  • #39 ??
    from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
  • #40 g_main_context_dispatch
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #41 ??
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #42 g_main_context_iteration
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #43 g_application_run
    from /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
  • #44 main
    at ../../src/main.c line 54

Comment 10 Johannes Schmid 2013-01-29 22:23:17 UTC
Found a wrong line in the markers_reload code but that's not the origin of the problem. Still looking for the leak...
Comment 11 John 2013-01-30 03:24:12 UTC
Johannes,

Would the changes of Carl-Anton (and yours) justify installed the latest version for testing?
Comment 12 Johannes Schmid 2013-01-30 11:45:22 UTC
John, partially yes, but I get the same problem as Sébastian but no crash. While trying to reproduce the crash (touch filename.c three times) I lost the content of a file once so that didn't happen again. You have been warned.

I still think there is some refcounting problem but didn't manage to fix it yesterday. Probably will have a look at it during the weekend.
Comment 13 Johannes Schmid 2013-02-20 19:34:15 UTC
There are quite a lot of changes in the reloading code now so that should definitily be revisted with the current master version!
Comment 14 John 2013-02-21 20:40:22 UTC
Wow... In this situation (from above):

> Consistently (=every time) Anjuta segfaults when I do:
>
> 1) change the contents of a file in the editor
> 2) Immediately try to close the tab (using the 'x' on it)
> 3) I get the 'want to save' dialog and click Save.

I don't get the segfault anymore, but now the file is truncated to
zero length!

I guess this may be the situation you mentioned.

Tried with two files, exactly the same result. No error messages
on the console.

This is not the reloading issue per se, but it is very worrying 
all the same. I'll try to use this version a little, to see if the
reloading works normally now. That problem was somewhat erratic, so
it may take some time.
Comment 15 Carl-Anton Ingmarsson 2013-02-21 21:55:12 UTC
Created attachment 237109 [details] [review]
sourceview: move all construction of Sourceview into constructed

To do this we make the reference to the SourceviewPlugin a property so
that it is set when constructed() is executed.

The benefit of this is that now is the plugin variable already set when the
Sourceview instance is passed to sourceview_io_new().
Comment 16 Carl-Anton Ingmarsson 2013-02-21 21:55:19 UTC
Created attachment 237110 [details] [review]
sourceview: keep a separate reference to AnjutaShell in SourceviewIO

So that we can reference it even though the parent Sourceview may have been
destroyed. This is/will be used when saving the file as a result of closing it.
Comment 17 Carl-Anton Ingmarsson 2013-02-21 21:55:24 UTC
Created attachment 237111 [details] [review]
sourceview: only cancel open operations when closing editor

We want an ongoing save operation to finish even though the sourceview
has been destroyed.
Comment 18 Carl-Anton Ingmarsson 2013-02-21 21:55:36 UTC
Created attachment 237112 [details] [review]
sourceview: add checks to SourceviewIO that the parent Sourceview is alive

The only function which is expected to run after the corresponding Sourceview
has been destroyed is on_save_finished()
Comment 19 Carl-Anton Ingmarsson 2013-02-21 21:55:41 UTC
Created attachment 237114 [details] [review]
sourceview: don't take extra refs during open/save

This is not needed anymore since:

 1) Open operations is cancelled when the Sourceview is destroyed.

 2) Save operations handles the case when the Sourceview is destroyed.
Comment 20 Johannes Schmid 2013-02-23 08:18:52 UTC
Review of attachment 237109 [details] [review]:

Definitly cleaner than before! Thanks!
Comment 21 Johannes Schmid 2013-02-23 08:21:26 UTC
Review of attachment 237110 [details] [review]:

Not sure about the cast but otherwise looks fine - thanks!

::: plugins/sourceview/sourceview-io.c
@@ +599,2 @@
 	sio->sv = sv;
+	g_object_add_weak_pointer (G_OBJECT (sv), (void**)&sio->sv);

Hmm, wouldn't it be better (to read) to cast to gpointer in that case?
Comment 22 Johannes Schmid 2013-02-23 08:26:56 UTC
Review of attachment 237111 [details] [review]:

Yep, makes sense to cancel only the open operation.
Comment 23 Johannes Schmid 2013-02-23 08:29:52 UTC
Review of attachment 237112 [details] [review]:

IMHO it would be nicer to have a cancel object and to disconnect the callback.

::: plugins/sourceview/sourceview-io.c
@@ +243,3 @@
+/*
+ * This function may be called after the corresponding Sourceview (sio->sv)
+ * has been destroyed.

Shouldn't we keep a cancel object in the SourceviewIO to avoid the possibility that this is even called?

@@ +441,3 @@
+		if (sio->sv == NULL)
+		{
+			g_warning ("Sourceview was destroyed without canceling SourceviewIO open operation");

Doesn't seem to be an error for me as we would expect this to be called in the current code under certain conditions.
Comment 24 Johannes Schmid 2013-02-23 08:30:28 UTC
Review of attachment 237114 [details] [review]:

Makes sense - dead code is good code ;)
Comment 25 Carl-Anton Ingmarsson 2013-02-23 11:12:04 UTC
(In reply to comment #23)
> Review of attachment 237112 [details] [review]:
> 
> IMHO it would be nicer to have a cancel object and to disconnect the callback.

Do you mean a GCancellable? The reason I'm not doing that is that we want the save operation to finish even though the Sourceview has been destroyed. E.g. this is used when one pushes "save" in the close document dialog.

> ::: plugins/sourceview/sourceview-io.c
> @@ +243,3 @@
> +/*
> + * This function may be called after the corresponding Sourceview (sio->sv)
> + * has been destroyed.
> 
> Shouldn't we keep a cancel object in the SourceviewIO to avoid the possibility
> that this is even called?
> 
> @@ +441,3 @@
> +        if (sio->sv == NULL)
> +        {
> +            g_warning ("Sourceview was destroyed without canceling
> SourceviewIO open operation");
> 
> Doesn't seem to be an error for me as we would expect this to be called in the
> current code under certain conditions.

This won't be called since the Sourceview calls sourceview_io_cancel_open() when it's destroyed.
Perhaps we should remove the sourceview_io_cancel_open() function and have SourceviewIO cancel it by itself when the Sourceview is destroyed? Using a weak ref to get notified when that happens.
Comment 26 Carl-Anton Ingmarsson 2013-02-23 11:16:31 UTC
Created attachment 237237 [details] [review]
sourceview: keep a separate reference to AnjutaShell in SourceviewIO

So that we can reference it even though the parent Sourceview may have been
destroyed. This is/will be used when saving the file as a result of closing it.
Comment 27 Johannes Schmid 2013-02-24 13:03:30 UTC
Review of attachment 237237 [details] [review]:

OK, thanks!
Comment 28 Johannes Schmid 2013-02-24 13:05:38 UTC
> This won't be called since the Sourceview calls sourceview_io_cancel_open()
> when it's destroyed.
> Perhaps we should remove the sourceview_io_cancel_open() function and have
> SourceviewIO cancel it by itself when the Sourceview is destroyed? Using a weak
> ref to get notified when that happens.

A weak reference sounds good to me.
Comment 29 Carl-Anton Ingmarsson 2013-02-24 18:53:40 UTC
Created attachment 237300 [details] [review]
sourceview: only cancel open operations when closing editor

We want an ongoing save operation to finish even though the sourceview
has been finalized.

Also rework the code so that SourceviewIO cancels the open operations
by itself when the Sourceview is finalized instead of having the
Sourceview be responsible for it.
Comment 30 Johannes Schmid 2013-02-24 20:07:31 UTC
Review of attachment 237300 [details] [review]:

Looks good - thanks!

Please commit all the patches and close the bug.
Comment 31 Carl-Anton Ingmarsson 2013-02-25 09:14:02 UTC
(In reply to comment #30)
> Review of attachment 237300 [details] [review]:
> 
> Looks good - thanks!
> 
> Please commit all the patches and close the bug.

I've commited the patches but I don't seem to have the permissions to mark the patches as commited or close the bug.
Comment 32 Johannes Schmid 2013-02-25 12:07:29 UTC
You should have the permissions now (at least for anjuta and gdl).