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 763908 - Cancel or remove pending internal asynchronous operations or sources during destruction
Cancel or remove pending internal asynchronous operations or sources during d...
Status: RESOLVED OBSOLETE
Product: gnome-photos
Classification: Applications
Component: general
3.19.x
Other All
: Normal normal
: ---
Assigned To: GNOME photos maintainer(s)
GNOME photos maintainer(s)
Depends on: 764781
Blocks:
 
 
Reported: 2016-03-19 10:00 UTC by Debarshi Ray
Modified: 2018-01-23 09:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
collection-icon-watcher: Rename a variable (1.34 KB, patch)
2016-03-19 10:02 UTC, Debarshi Ray
committed Details | Review
collection-icon-watcher: Cancel cursor_next_async during destruction (4.31 KB, patch)
2016-03-19 10:03 UTC, Debarshi Ray
committed Details | Review
embed: Don't leak self when load_show_id is removed before the timeout (1.52 KB, patch)
2016-03-19 10:04 UTC, Debarshi Ray
committed Details | Review
embed: Remove load_show_id during destruction (1.26 KB, patch)
2016-03-19 10:04 UTC, Debarshi Ray
committed Details | Review
preview-nav-buttons: Remove auto_hide_id during destruction (1.54 KB, patch)
2016-03-19 10:05 UTC, Debarshi Ray
committed Details | Review
tracker-controller: Rename a variable (1.26 KB, patch)
2016-03-21 14:28 UTC, Rafael Fonseca
committed Details | Review
tracker-controller: Cancel cursor_next_async during destruction (3.06 KB, patch)
2016-03-21 14:29 UTC, Rafael Fonseca
none Details | Review
export-notification: Remove timeout_id during destruction (1.64 KB, patch)
2016-03-21 14:40 UTC, Rafael Fonseca
committed Details | Review
indexing-notification: Remove timeout_id during destruction (1.71 KB, patch)
2016-03-21 14:44 UTC, Rafael Fonseca
committed Details | Review
delete-notification: Remove timeout_id during destruction (1.63 KB, patch)
2016-03-21 14:46 UTC, Rafael Fonseca
committed Details | Review
done-notification: Remove timeout_id during destruction (1.60 KB, patch)
2016-03-21 14:48 UTC, Rafael Fonseca
committed Details | Review
offset-controller: Rename variable (1.17 KB, patch)
2016-03-21 15:20 UTC, Rafael Fonseca
committed Details | Review
offset-controller: Check for error from sparql_cursor_next_finish (1.47 KB, patch)
2016-03-21 15:20 UTC, Rafael Fonseca
none Details | Review
offset-controller: Cancel cursor_next_async during destruction (3.14 KB, patch)
2016-03-21 15:21 UTC, Rafael Fonseca
none Details | Review
offset-controller: Cancel cursor_next_async during destruction (3.14 KB, patch)
2016-03-21 15:33 UTC, Rafael Fonseca
committed Details | Review
offset-controller: Cancel tracker_queue_select during destruction (2.36 KB, patch)
2016-03-21 15:45 UTC, Rafael Fonseca
reviewed Details | Review
done-notification: Cancel item_process_async during destruction (3.34 KB, patch)
2016-03-21 16:00 UTC, Rafael Fonseca
none Details | Review
done-notification: Remove duplicated g_application_release (1.09 KB, patch)
2016-03-21 16:00 UTC, Rafael Fonseca
none Details | Review
done-notification: Cancel pipeline_save_async during destruction (1.85 KB, patch)
2016-03-21 16:01 UTC, Rafael Fonseca
none Details | Review
tool-crop: Cancel item_process_async during destruction (3.16 KB, patch)
2016-03-21 16:07 UTC, Rafael Fonseca
none Details | Review
properties-dialog: Move common code to its own function (2.09 KB, patch)
2016-03-21 16:19 UTC, Rafael Fonseca
committed Details | Review
properties-dialog: Remove title_entry_timeout during destruction (1.42 KB, patch)
2016-03-21 16:20 UTC, Rafael Fonseca
none Details | Review
tracker-change-monitor: Move code to its own function (1.52 KB, patch)
2016-03-21 16:28 UTC, Rafael Fonseca
committed Details | Review
tracker-change-monitor: Remove pending_events_id during destruction (1.73 KB, patch)
2016-03-21 16:29 UTC, Rafael Fonseca
committed Details | Review
preview-view: Cancel pipeline_save_async during destruction (3.08 KB, patch)
2016-03-21 16:36 UTC, Rafael Fonseca
none Details | Review
tracker-controller: Rename cancellable (3.31 KB, patch)
2016-03-21 17:32 UTC, Rafael Fonseca
none Details | Review
tracker-controller: Cancel cursor_next_async during destruction (4.15 KB, patch)
2016-03-21 17:33 UTC, Rafael Fonseca
needs-work Details | Review
tracker-controller: Clear queue_cancellable on destruction (970 bytes, patch)
2016-03-21 17:33 UTC, Rafael Fonseca
none Details | Review
offset-controller: Handle errors from tracker_sparql_cursor_next_finish (1.58 KB, patch)
2016-03-22 10:08 UTC, Debarshi Ray
committed Details | Review
offset-controller: Cancel cursor_next_async during destruction (3.17 KB, patch)
2016-03-22 10:09 UTC, Debarshi Ray
committed Details | Review
preview-view: Cancel photos_base_item_process_async during destruction (5.08 KB, patch)
2016-03-22 11:27 UTC, Debarshi Ray
committed Details | Review
offset-controller: Cancel cursor_next_async during destruction (3.28 KB, patch)
2016-03-22 12:40 UTC, Rafael Fonseca
reviewed Details | Review
local-item: Cancel trash_item during destruction (3.50 KB, patch)
2016-03-22 15:32 UTC, Rafael Fonseca
committed Details | Review
local-item: Cancel g_file_trash_async during destruction (3.27 KB, patch)
2016-03-23 11:09 UTC, Debarshi Ray
committed Details | Review
tool-crop: Cancel item_process_async during destruction (3.10 KB, patch)
2016-03-23 11:56 UTC, Debarshi Ray
committed Details | Review
base-item: Cancel g_file_query_info_async during destruction (3.59 KB, patch)
2016-03-23 19:15 UTC, Umang Jain
committed Details | Review
base-item: Don't leak the GFileInfo (1023 bytes, patch)
2016-03-24 11:33 UTC, Debarshi Ray
committed Details | Review
base-item: Cancel g_file_query_info_async during destruction (3.51 KB, patch)
2016-03-24 11:34 UTC, Debarshi Ray
committed Details | Review
Cancel g_file_read_async during destruction (2.67 KB, patch)
2016-03-25 02:51 UTC, Umang Jain
none Details | Review
base-item: Cancel g_file_read_async during destruction (2.69 KB, patch)
2016-03-25 02:58 UTC, Umang Jain
none Details | Review
base-item: Cancel g_file_read_async during destruction (2.69 KB, patch)
2016-03-25 04:40 UTC, Umang Jain
none Details | Review
base-item: Check for errors while loading the item for printing (1018 bytes, patch)
2016-03-25 05:17 UTC, Umang Jain
committed Details | Review
Don't leak GFileInfo (998 bytes, patch)
2016-03-25 07:34 UTC, Umang Jain
committed Details | Review
base-item: Cancel photos_base_item_refresh_icon during destruction (2.47 KB, patch)
2016-03-25 08:35 UTC, Umang Jain
committed Details | Review
base-item: Cancel gdk_pixbuf_new_from_stream_async during destruction (2.99 KB, patch)
2016-03-25 12:11 UTC, Umang Jain
committed Details | Review
properties-dialog: Move common code to its own function (1.83 KB, patch)
2016-04-01 11:44 UTC, Debarshi Ray
committed Details | Review
properties-dialog: Remove title_entry_timeout during destruction (1.70 KB, patch)
2016-04-01 12:03 UTC, Debarshi Ray
none Details | Review
done-notification: Remove timeout_id during destruction (1.52 KB, patch)
2016-04-01 15:27 UTC, Debarshi Ray
committed Details | Review
Fix the reference counting for NotificationManager (5.27 KB, patch)
2016-04-01 22:25 UTC, Debarshi Ray
committed Details | Review
base-item: Cancel gdk_pixbuf_new_from_stream_async during destruction (3.16 KB, patch)
2016-04-05 09:51 UTC, Debarshi Ray
committed Details | Review
properties-dialog: remove title_entry_timeout during destruction (2.76 KB, patch)
2016-04-05 12:39 UTC, Rafael Fonseca
none Details | Review
properties-dialog: Remove title_entry_timeout during destruction (2.69 KB, patch)
2016-04-05 13:18 UTC, Rafael Fonseca
committed Details | Review
base-item: Shuffle some code around (1.30 KB, patch)
2016-04-12 08:00 UTC, Debarshi Ray
committed Details | Review
base-item: Check for errors while loading the item for printing (1.07 KB, patch)
2016-04-12 08:18 UTC, Debarshi Ray
committed Details | Review
base-item: Reset the GError before using it (1.52 KB, patch)
2016-04-12 08:19 UTC, Debarshi Ray
committed Details | Review
base-item: Cancel g_file_read_async during destruction (2.50 KB, patch)
2016-04-12 17:34 UTC, Umang Jain
none Details | Review
base-item: Cancel g_file_read_async during destruction (2.70 KB, patch)
2016-04-12 19:33 UTC, Umang Jain
committed Details | Review
preview-view: Cancel pipeline_save_async during destruction (2.33 KB, patch)
2016-04-15 13:12 UTC, Rafael Fonseca
none Details | Review
done-notification: cancel item_process_async during destruction (3.42 KB, patch)
2016-04-15 13:26 UTC, Rafael Fonseca
needs-work Details | Review
done-notification: Cancel pipeline_save_async during destruction (1.80 KB, patch)
2016-04-15 13:27 UTC, Rafael Fonseca
needs-work Details | Review
preview-view: Cancel pipeline_save_async during destruction (2.66 KB, patch)
2016-06-17 17:34 UTC, Debarshi Ray
none Details | Review
preview-view: Hold the UI while saving the pipeline (2.75 KB, patch)
2016-06-18 08:03 UTC, Debarshi Ray
committed Details | Review
application, done-notification: Use a GAction to handle the revert (9.26 KB, patch)
2016-07-14 09:12 UTC, Debarshi Ray
committed Details | Review
done-notification: Remove unnecessary references (2.56 KB, patch)
2016-07-21 17:48 UTC, Debarshi Ray
committed Details | Review
application, done-notification: Use a GAction to handle the revert (9.83 KB, patch)
2016-07-21 17:49 UTC, Debarshi Ray
committed Details | Review
tracker-controller: Don't use g_cancellable_reset (986 bytes, patch)
2016-12-01 09:17 UTC, Debarshi Ray
none Details | Review
tracker-controller: Handle tracker_sparql_cursor_next_finish errors (1.56 KB, patch)
2016-12-01 09:18 UTC, Debarshi Ray
none Details | Review

Description Debarshi Ray 2016-03-19 10:00:31 UTC
We cancel (g_cancellable_cancel) or remove (g_source_remove) pending internal asynchronous operations or sources when an object is destroyed.

Right now, we hold a reference to the object itself (g_object_ref (self)) to delay the destruction while something is pending. This approach is easier to implement, but has a few drawbacks:

(a) Code outside such objects (ie. their clients) are not expecting them to stay alive after they have dropped all their references. Therefore, if the pending asynchronous operation or source has any visible side-effects (eg., emitting a signal) then bad things can happen (eg., crashes).

(b) All objects might not be destroyed during shutdown. This is usually not a big issue because the process is about to die anyway. In our case, though, gegl_exit complains if some GeglBuffers were still alive.

(c) Not cancelling or removing pending items is a bit wasteful.

I have a few patches to get this started.

Feel free to pick it up. Just make sure that you split it into smaller patches (eg., one for object or operation/source) so that it is easier to review and test against regressions.
Comment 1 Debarshi Ray 2016-03-19 10:02:38 UTC
Created attachment 324323 [details] [review]
collection-icon-watcher: Rename a variable
Comment 2 Debarshi Ray 2016-03-19 10:03:48 UTC
Created attachment 324324 [details] [review]
collection-icon-watcher: Cancel cursor_next_async during destruction
Comment 3 Debarshi Ray 2016-03-19 10:04:14 UTC
Created attachment 324325 [details] [review]
embed: Don't leak self when load_show_id is removed before the timeout
Comment 4 Debarshi Ray 2016-03-19 10:04:46 UTC
Created attachment 324326 [details] [review]
embed: Remove load_show_id during destruction
Comment 5 Debarshi Ray 2016-03-19 10:05:15 UTC
Created attachment 324327 [details] [review]
preview-nav-buttons: Remove auto_hide_id during destruction
Comment 6 Rafael Fonseca 2016-03-21 14:28:57 UTC
Created attachment 324438 [details] [review]
tracker-controller: Rename a variable
Comment 7 Rafael Fonseca 2016-03-21 14:29:23 UTC
Created attachment 324439 [details] [review]
tracker-controller: Cancel cursor_next_async during destruction
Comment 8 Rafael Fonseca 2016-03-21 14:40:29 UTC
Created attachment 324440 [details] [review]
export-notification: Remove timeout_id during destruction
Comment 9 Rafael Fonseca 2016-03-21 14:44:25 UTC
Created attachment 324441 [details] [review]
indexing-notification: Remove timeout_id during destruction
Comment 10 Rafael Fonseca 2016-03-21 14:46:40 UTC
Created attachment 324442 [details] [review]
delete-notification: Remove timeout_id during destruction
Comment 11 Rafael Fonseca 2016-03-21 14:48:38 UTC
Created attachment 324443 [details] [review]
done-notification: Remove timeout_id during destruction
Comment 12 Rafael Fonseca 2016-03-21 15:20:10 UTC
Created attachment 324446 [details] [review]
offset-controller: Rename variable
Comment 13 Rafael Fonseca 2016-03-21 15:20:50 UTC
Created attachment 324447 [details] [review]
offset-controller: Check for error from sparql_cursor_next_finish
Comment 14 Rafael Fonseca 2016-03-21 15:21:15 UTC
Created attachment 324448 [details] [review]
offset-controller: Cancel cursor_next_async during destruction
Comment 15 Rafael Fonseca 2016-03-21 15:33:05 UTC
Created attachment 324449 [details] [review]
offset-controller: Cancel cursor_next_async during destruction

attaching correct version of the patch.
Comment 16 Rafael Fonseca 2016-03-21 15:45:43 UTC
Created attachment 324452 [details] [review]
offset-controller: Cancel tracker_queue_select during destruction
Comment 17 Rafael Fonseca 2016-03-21 16:00:05 UTC
Created attachment 324474 [details] [review]
done-notification: Cancel item_process_async during destruction
Comment 18 Rafael Fonseca 2016-03-21 16:00:39 UTC
Created attachment 324475 [details] [review]
done-notification: Remove duplicated g_application_release
Comment 19 Rafael Fonseca 2016-03-21 16:01:03 UTC
Created attachment 324476 [details] [review]
done-notification: Cancel pipeline_save_async during destruction
Comment 20 Rafael Fonseca 2016-03-21 16:07:49 UTC
Created attachment 324477 [details] [review]
tool-crop: Cancel item_process_async during destruction
Comment 21 Rafael Fonseca 2016-03-21 16:19:53 UTC
Created attachment 324479 [details] [review]
properties-dialog: Move common code to its own function
Comment 22 Rafael Fonseca 2016-03-21 16:20:19 UTC
Created attachment 324480 [details] [review]
properties-dialog: Remove title_entry_timeout during destruction
Comment 23 Rafael Fonseca 2016-03-21 16:28:25 UTC
Created attachment 324481 [details] [review]
tracker-change-monitor: Move code to its own function
Comment 24 Rafael Fonseca 2016-03-21 16:29:01 UTC
Created attachment 324482 [details] [review]
tracker-change-monitor: Remove pending_events_id during destruction
Comment 25 Rafael Fonseca 2016-03-21 16:36:18 UTC
Created attachment 324485 [details] [review]
preview-view: Cancel pipeline_save_async during destruction
Comment 26 Debarshi Ray 2016-03-21 17:18:08 UTC
Review of attachment 324446 [details] [review]:

++
Comment 27 Debarshi Ray 2016-03-21 17:20:18 UTC
Review of attachment 324438 [details] [review]:

++

By convention, we don't add append a full stop (ie. '.') to the subject of the commit message. See: https://wiki.gnome.org/Git/CommitMessages
Comment 28 Rafael Fonseca 2016-03-21 17:32:15 UTC
Created attachment 324488 [details] [review]
tracker-controller: Rename cancellable
Comment 29 Rafael Fonseca 2016-03-21 17:33:07 UTC
Created attachment 324489 [details] [review]
tracker-controller: Cancel cursor_next_async during destruction

Attaching correct version of the patch.
Comment 30 Rafael Fonseca 2016-03-21 17:33:34 UTC
Created attachment 324490 [details] [review]
tracker-controller: Clear queue_cancellable on destruction
Comment 31 Debarshi Ray 2016-03-22 09:58:37 UTC
Review of attachment 324447 [details] [review]:

Thanks for the patch, Rafael. Looks good except one small issue:

::: src/photos-offset-controller.c
@@ +75,3 @@
+  if (error != NULL)
+    {
+      g_warning ("Unable to query item: %s", error->message);

We are trying to query the number of items in a particular mode (overview, favorites, collections, search), not an individual item. Therefore, something like "Unable to query the item count" would be more correct.
Comment 32 Debarshi Ray 2016-03-22 10:04:55 UTC
Review of attachment 324449 [details] [review]:

::: src/photos-offset-controller.c
@@ +78,3 @@
+        {
+          g_error_free (error);
+          return;

Pedantically speaking, we should also use 'goto out' here for the tracker_sparql_cursor_close call. Doing that will simplify the error handling a bit.

The bigger question is, whether we need to explicitly close the cursor at all? My understanding of the TrackerSparqlCursor implementation is that it will close the cursor when it is destroyed due to the last reference being dropped. We can address that in a separate patch, though.

@@ +118,3 @@
 
+  tracker_sparql_cursor_next_async (cursor,
+                                    priv->cancellable,

self->priv->cancellable, else it won't compile. :)

@@ +150,3 @@
   priv = self->priv;
 
+  priv->cancellable = g_cancellable_new ();

'cancellable' is missing from the Private struct. :)
Comment 33 Debarshi Ray 2016-03-22 10:08:17 UTC
Created attachment 324528 [details] [review]
offset-controller: Handle errors from tracker_sparql_cursor_next_finish

Fixed and pushed.
Comment 34 Debarshi Ray 2016-03-22 10:09:30 UTC
Created attachment 324529 [details] [review]
offset-controller: Cancel cursor_next_async during destruction

Fixed and pushed.
Comment 35 Debarshi Ray 2016-03-22 11:24:43 UTC
Review of attachment 324452 [details] [review]:

Thanks for the patch, Rafael.

This patch looks OK, but I think it has exposed a bug in tracker_sparql_connection_query_async/finish. Namely, that it doesn't throw G_IO_ERROR_CANCELLED if the operation is cancelled. This means that we try to use an invalid PhotosOffsetController, if the application is quit while the call was still pending. A quick look at the generated C code for the corresponding Vala bits didn't reveal any use of g_simple_async_result_set_check_cancellable, which makes me suspicious. (The Vala compiler still generates code using GSimpleAsyncResult, not GTask.)

Let's sort this out before pushing this.
Comment 36 Debarshi Ray 2016-03-22 11:27:11 UTC
Created attachment 324532 [details] [review]
preview-view: Cancel photos_base_item_process_async during destruction
Comment 37 Rafael Fonseca 2016-03-22 12:40:05 UTC
Created attachment 324536 [details] [review]
offset-controller: Cancel cursor_next_async during destruction

Addressing raised points.
Comment 38 Debarshi Ray 2016-03-22 15:20:54 UTC
Review of attachment 324536 [details] [review]:

I had already pushed a fixed version of this patch. Sorry for the confusion.
Comment 39 Rafael Fonseca 2016-03-22 15:32:01 UTC
Created attachment 324544 [details] [review]
local-item: Cancel trash_item during destruction
Comment 40 Debarshi Ray 2016-03-23 11:08:26 UTC
Review of attachment 324544 [details] [review]:

Thanks for the patch. A few minor nits, but otherwise looks perfect.

::: src/photos-local-item.c
@@ +177,3 @@
+          const gchar *uri;
+
+          self = PHOTOS_LOCAL_ITEM (user_data);

Nitpick: since we are only assigning self inside the if, would be better to move the definition here too.

@@ +207,2 @@
 static void
+photos_local_item_dispose (GObject *object)

Nitpick: would be nice to move it lower to retain the alphabetical ordering.
Comment 41 Debarshi Ray 2016-03-23 11:09:18 UTC
Created attachment 324583 [details] [review]
local-item: Cancel g_file_trash_async during destruction

Fixed and pushed.
Comment 42 Debarshi Ray 2016-03-23 11:55:22 UTC
Review of attachment 324477 [details] [review]:

::: src/photos-tool-crop.c
@@ +907,3 @@
+          g_error_free (error);
+          return;
+        }

This can be simplified, as in some of the other patches.
Comment 43 Debarshi Ray 2016-03-23 11:56:07 UTC
Created attachment 324586 [details] [review]
tool-crop: Cancel item_process_async during destruction

Fixed and pushed.
Comment 44 Debarshi Ray 2016-03-23 14:03:45 UTC
Review of attachment 324485 [details] [review]:

::: src/photos-preview-view.c
@@ +528,1 @@
   g_application_hold (app);

I would also remove the g_application_hold/release.

It made sense when we used to hold our own reference to PreviewView. If someone quit the application (which means MainWindow getting destroyed), then this would keep the process alive until the callback was invoked, and the ref on PreviewView would ensure that the callback didn't run into memory errors, even though some of the widgets outside PreviewView  might already be gone.

Now, with the ref on PreviewView gone, it doesn't make sense to keep the  process alive.

In future, we need a more elaborate structure in place to stop the main window from disappearing during such operations. We can take ideas from gedit, for example.
Comment 45 Umang Jain 2016-03-23 19:15:35 UTC
Created attachment 324621 [details] [review]
base-item: Cancel g_file_query_info_async during destruction
Comment 46 Debarshi Ray 2016-03-24 11:32:34 UTC
Review of attachment 324621 [details] [review]:

The patch looks fine, except that it doesn't compile. See below.

::: src/photos-base-item.c
@@ +679,1 @@
   info = g_file_query_info_finish (file, res, &error);

We were leaking info. :(

@@ +683,3 @@
+        {
+          self = PHOTOS_BASE_ITEM (user_data);
+          priv = self->priv;

I find it cleaner to assign self and priv in only place in the function. See some of the other async operations for ideas.

@@ +684,3 @@
+          self = PHOTOS_BASE_ITEM (user_data);
+          priv = self->priv;
+          g_warning ("Unable to query info for file at %s: %s", priv->uri, error->message);

eg., we can use g_file_get_uri instead of priv->uri, since priv won't be defined here.

@@ +1507,3 @@
+    {
+       g_cancellable_cancel (self->cancellable);
+       g_clear_object (&self->cancellable);

s/self/priv/g
Comment 47 Debarshi Ray 2016-03-24 11:33:17 UTC
Created attachment 324669 [details] [review]
base-item: Don't leak the GFileInfo
Comment 48 Debarshi Ray 2016-03-24 11:34:04 UTC
Created attachment 324671 [details] [review]
base-item: Cancel g_file_query_info_async during destruction

Fixed and pushed.
Comment 49 Debarshi Ray 2016-03-24 11:37:57 UTC
Review of attachment 324479 [details] [review]:

Thanks, Rafael. Looks good except one minor issue.

::: src/photos-properties-dialog.c
@@ -116,3 @@
   photos_utils_set_edited_name (self->urn, new_title);
 
-  g_object_unref (self);

This should be part of the next patch.
Comment 50 Umang Jain 2016-03-25 02:51:29 UTC
Created attachment 324735 [details] [review]
Cancel g_file_read_async during destruction
Comment 51 Umang Jain 2016-03-25 02:58:43 UTC
Created attachment 324736 [details] [review]
base-item: Cancel g_file_read_async during destruction
Comment 52 Umang Jain 2016-03-25 04:40:57 UTC
Created attachment 324738 [details] [review]
base-item: Cancel g_file_read_async during destruction
Comment 53 Umang Jain 2016-03-25 05:17:28 UTC
Created attachment 324739 [details] [review]
base-item: Check for errors while loading the item for printing
Comment 54 Umang Jain 2016-03-25 07:34:52 UTC
Created attachment 324741 [details] [review]
Don't leak GFileInfo
Comment 55 Umang Jain 2016-03-25 08:35:37 UTC
Created attachment 324742 [details] [review]
base-item: Cancel photos_base_item_refresh_icon during destruction
Comment 56 Umang Jain 2016-03-25 12:11:31 UTC
Created attachment 324746 [details] [review]
base-item: Cancel gdk_pixbuf_new_from_stream_async during destruction
Comment 57 Rafael Fonseca 2016-03-25 12:54:39 UTC
Review of attachment 324746 [details] [review]:

::: src/photos-base-item.c
@@ +607,3 @@
+  priv = self->priv;
+
+	  file = G_FILE (g_object_get_data (G_OBJECT (stream), "file"));

Why are you separating the error condition handling in two parts? This block should be joined with the one above. It's all about the same error handling: failed to get a thumbnail, delete the file, set the fail condition, leave. That's how it was before. You just need to add the early leave in case the object is being destroyed.
Comment 58 Rafael Fonseca 2016-03-25 12:59:42 UTC
Review of attachment 324741 [details] [review]:

r+
Comment 59 Rafael Fonseca 2016-03-25 13:03:29 UTC
Review of attachment 324739 [details] [review]:

::: src/photos-base-item.c
@@ +1483,3 @@
   GtkPrintOperationResult print_res;
 
+  node = photos_base_item_load_finish (self, res, &error);

Note that error is being used below for the gtk_print_operation_run. I think it's a good idea to set it to NULL before that, just to make sure we're not re-using the value somehow.
Comment 60 Debarshi Ray 2016-04-01 11:43:34 UTC
Review of attachment 324479 [details] [review]:

::: src/photos-properties-dialog.c
@@ +108,2 @@
+static void
+photos_properties_dialog_remove_timout (PhotosPropertiesDialog *self)

Typo alert: "remove_timeout", not "remove_timout". :)
Comment 61 Debarshi Ray 2016-04-01 11:44:21 UTC
Created attachment 325149 [details] [review]
properties-dialog: Move common code to its own function

Fixed and pushed.
Comment 62 Debarshi Ray 2016-04-01 12:03:16 UTC
Created attachment 325150 [details] [review]
properties-dialog: Remove title_entry_timeout during destruction

Rebased on top of master.
Comment 63 Debarshi Ray 2016-04-01 12:10:26 UTC
Review of attachment 325150 [details] [review]:

Thanks, Rafael. There is one problem:

::: src/photos-properties-dialog.c
@@ +521,3 @@
     }
 
+  photos_properties_dialog_remove_timeout (self);

Unlike most timeouts, photos_properties_dialog_title_entry_timeout has a side-effect. ie. it calls photos_utils_set_edited_name to change the title/name of the item in tracker's database. So, if the dialog was getting destroyed before the timeout had a chance to run, we would be missing the update.

Therefore, I think, we should somehow do the update in dispose. We need to be careful, though, because dispose can get called multiple times. eg., with a if (title_entry_timeout != 0).
Comment 64 Rafael Fonseca 2016-04-01 12:21:27 UTC
(In reply to Debarshi Ray from comment #63)
> Review of attachment 325150 [details] [review] [review]:
> 
> Thanks, Rafael. There is one problem:
> 
> ::: src/photos-properties-dialog.c
> @@ +521,3 @@
>      }
>  
> +  photos_properties_dialog_remove_timeout (self);
> 
> Unlike most timeouts, photos_properties_dialog_title_entry_timeout has a
> side-effect. ie. it calls photos_utils_set_edited_name to change the
> title/name of the item in tracker's database. So, if the dialog was getting
> destroyed before the timeout had a chance to run, we would be missing the
> update.
> 
> Therefore, I think, we should somehow do the update in dispose. We need to
> be careful, though, because dispose can get called multiple times. eg., with
> a if (title_entry_timeout != 0).

So if I want to discard the modification I have to manually revert the name to what it was before?
Comment 65 Debarshi Ray 2016-04-01 12:48:57 UTC
Review of attachment 324442 [details] [review]:

Looks good to me.
Comment 66 Debarshi Ray 2016-04-01 12:54:52 UTC
Review of attachment 324440 [details] [review]:

Looks good to me.
Comment 67 Debarshi Ray 2016-04-01 15:10:45 UTC
(In reply to Rafael Fonseca from comment #64)
> (In reply to Debarshi Ray from comment #63)
> > Review of attachment 325150 [details] [review] [review] [review]:
> > ::: src/photos-properties-dialog.c
> > @@ +521,3 @@
> >      }
> >  
> > +  photos_properties_dialog_remove_timeout (self);
> > 
> > Unlike most timeouts, photos_properties_dialog_title_entry_timeout has a
> > side-effect. ie. it calls photos_utils_set_edited_name to change the
> > title/name of the item in tracker's database. So, if the dialog was getting
> > destroyed before the timeout had a chance to run, we would be missing the
> > update.
> > 
> > Therefore, I think, we should somehow do the update in dispose. We need to
> > be careful, though, because dispose can get called multiple times. eg., with
> > a if (title_entry_timeout != 0).
> 
> So if I want to discard the modification I have to manually revert the name
> to what it was before?

The entry in the properties dialog is instant apply. ie. it updates the title as you type. The timeout is there to batch the keystrokes. So, currently, there is no way to undo the modification. Maybe we can present an in-app notification with an "undo" button once you close the dialog? We can decide it later as it is not relevant to this bug. :)

I was worried about the case where the user types and manages to close the dialog before the timeout. It is hard to physically achieve that feat, but who knows? In that case, we will miss the last few keystrokes if we don't do the update during destruction. eg., the title could be left as "new ti" instead of "new title".
Comment 68 Debarshi Ray 2016-04-01 15:26:57 UTC
Review of attachment 324443 [details] [review]:

::: src/photos-done-notification.c
@@ +209,3 @@
+  self->timeout_id = g_timeout_add_seconds (DONE_TIMEOUT,
+                                            photos_done_notification_timeout,
+                                            self);

Could be on the same line. Given all the long GObject/C names and modern terminals being able to accommodate more than 80 characters, it is OK to go till 120 characters in the code.
Comment 69 Debarshi Ray 2016-04-01 15:27:43 UTC
Created attachment 325162 [details] [review]
done-notification: Remove timeout_id during destruction

Fixed the formatting and pushed.
Comment 70 Debarshi Ray 2016-04-01 22:23:12 UTC
Review of attachment 324441 [details] [review]:

Looks good to me.
Comment 71 Debarshi Ray 2016-04-01 22:25:00 UTC
Created attachment 325192 [details] [review]
Fix the reference counting for NotificationManager
Comment 72 Debarshi Ray 2016-04-05 09:50:03 UTC
Review of attachment 324746 [details] [review]:

For some reason this is not applying anymore. :/

::: src/photos-base-item.c
@@ +607,3 @@
+  priv = self->priv;
+
+  if (pixbuf == NULL)

The problem is that the non-cancelled error path needs self. So we either need to duplicate the self/priv assignment, or we have to split the error path.
Comment 73 Debarshi Ray 2016-04-05 09:51:04 UTC
Created attachment 325405 [details] [review]
base-item: Cancel gdk_pixbuf_new_from_stream_async during destruction

Rebased and pushed.
Comment 74 Debarshi Ray 2016-04-05 10:00:31 UTC
Review of attachment 324482 [details] [review]:

Thanks Rafael. Looks good to me.
Comment 75 Debarshi Ray 2016-04-05 10:00:38 UTC
Review of attachment 324481 [details] [review]:

++
Comment 76 Rafael Fonseca 2016-04-05 12:39:50 UTC
Created attachment 325418 [details] [review]
properties-dialog: remove title_entry_timeout during destruction

New patch fixing raised issue.
Comment 77 Rafael Fonseca 2016-04-05 13:18:01 UTC
Created attachment 325429 [details] [review]
properties-dialog: Remove title_entry_timeout during destruction

Fixed version.
Comment 78 Debarshi Ray 2016-04-05 13:31:05 UTC
Review of attachment 325429 [details] [review]:

Looks good to me. By the way, this also fixes leaking a reference to PropertiesDialog when requeuing the timeout. :)
Comment 79 Debarshi Ray 2016-04-12 07:58:19 UTC
Review of attachment 324738 [details] [review]:

Thanks, Umang. A few comments:

::: src/photos-base-item.c
@@ +621,1 @@
   PhotosBaseItemPrivate *priv = self->priv;

We can't touch self and priv before we have handled any possible errors. If we received a G_IO_ERROR_CANCELLED, then they are already destroyed. Surely you know about commit 5eead6b0772b0d4d8b2ac60ae41b615956a7697a :)

@@ +643,2 @@
     }
 

This is where we should assign self and priv.

@@ +644,3 @@
 
+      if (stream == NULL)
+	{

Broken alignment.

@@ +647,3 @@
+	  priv->failed_thumbnailing = TRUE;
+	  priv->thumb_path = NULL;
+	  g_file_delete_async (file, G_PRIORITY_DEFAULT, NULL, NULL, NULL);

Nitpick: put the g_file_delete_async in the error handling block above like in commit 5eead6b0772b0d4d8b2ac60ae41b615956a7697a

@@ +659,2 @@
  out:
+  g_object_unref (stream);

This isn't quite right. If you put it after 'out', which is a good idea, then you need to use g_clear_object, because stream can be NULL and g_object_unref doesn't like NULL inputs.

Also, this bit is an unrelated change, so it's better to use a separate patch.
Comment 80 Debarshi Ray 2016-04-12 08:00:14 UTC
Created attachment 325769 [details] [review]
base-item: Shuffle some code around

This is the g_object_unref to g_clear_object part of the previous patch.
Comment 81 Debarshi Ray 2016-04-12 08:12:30 UTC
Review of attachment 324739 [details] [review]:

::: src/photos-base-item.c
@@ +1493,2 @@
   if (node == NULL)
     goto out;

If you are already checking 'error', then this is redundant.
Comment 82 Debarshi Ray 2016-04-12 08:18:46 UTC
Created attachment 325771 [details] [review]
base-item: Check for errors while loading the item for printing
Comment 83 Debarshi Ray 2016-04-12 08:19:58 UTC
Created attachment 325772 [details] [review]
base-item: Reset the GError before using it

Addressing Rafael's comment about the resetting the GError, which I missed earlier.
Comment 84 Debarshi Ray 2016-04-12 08:31:00 UTC
Review of attachment 324742 [details] [review]:

Thanks, looks good to me. Pushed.
Comment 85 Umang Jain 2016-04-12 17:34:33 UTC
Created attachment 325814 [details] [review]
base-item: Cancel g_file_read_async during destruction
Comment 86 Debarshi Ray 2016-04-12 18:18:41 UTC
Review of attachment 325814 [details] [review]:

Thanks, Umang. Unfortunately, this version introduces two new problems:

::: src/photos-base-item.c
@@ +655,3 @@
+	  g_free (uri);
+	  g_error_free (error);
+	  goto out;

This goto can't be here because we want to keep going.

@@ +693,2 @@
                      photos_base_item_refresh_thumb_path_read,
+                     self);

The corresponding g_object_unref (self) needs to be removed from the callback.
Comment 87 Umang Jain 2016-04-12 19:33:10 UTC
Created attachment 325819 [details] [review]
base-item: Cancel g_file_read_async during destruction
Comment 88 Debarshi Ray 2016-04-13 13:56:04 UTC
Review of attachment 325819 [details] [review]:

Looks good to me.
Comment 89 Debarshi Ray 2016-04-14 07:25:31 UTC
Review of attachment 324474 [details] [review]:

::: src/photos-done-notification.c
@@ +163,1 @@
   g_application_hold (app);

Same thing as comment 44
Comment 90 Debarshi Ray 2016-04-14 07:26:53 UTC
Review of attachment 324476 [details] [review]:

::: src/photos-done-notification.c
@@ +139,1 @@
   g_application_hold (app);

Same thing as comment 44
Comment 91 Debarshi Ray 2016-04-14 07:32:25 UTC
Review of attachment 324475 [details] [review]:

Apart from the following comment, this depends on the other two patches touching this code.

::: src/photos-done-notification.c
@@ -107,3 @@
 
-  app = g_application_get_default ();
-  g_application_release (app);

We have 2 holds (one for processing and one for saving), so we need 2 releases, right? Or am I missing something?
Comment 92 Rafael Fonseca 2016-04-15 13:12:20 UTC
Created attachment 326094 [details] [review]
preview-view: Cancel pipeline_save_async during destruction

Addressing raised points.
Comment 93 Rafael Fonseca 2016-04-15 13:26:32 UTC
Created attachment 326096 [details] [review]
done-notification: cancel item_process_async during destruction

Fixing issues.
Comment 94 Rafael Fonseca 2016-04-15 13:27:12 UTC
Created attachment 326097 [details] [review]
done-notification: Cancel pipeline_save_async during destruction

Fixing issues.
Comment 95 Debarshi Ray 2016-06-17 17:34:57 UTC
Created attachment 329969 [details] [review]
preview-view: Cancel pipeline_save_async during destruction

I took the liberty to tweak this patch to leverage the new API in bug 764076. I added a separate warning to indicate a cancellation due to unintended destruction of PhotosPreviewView in the middle of the critical pipeline_save_async operation.

If this works out, then we should adjust the rest of the patches involving similar critical operations (and close this bug).
Comment 96 Debarshi Ray 2016-06-18 08:03:34 UTC
Created attachment 329988 [details] [review]
preview-view: Hold the UI while saving the pipeline
Comment 97 Debarshi Ray 2016-06-18 08:05:20 UTC
Comment on attachment 329988 [details] [review]
preview-view: Hold the UI while saving the pipeline

Pushed to master.
Comment 98 Debarshi Ray 2016-06-18 10:03:42 UTC
Review of attachment 326096 [details] [review]:

There is a problem with this. I am sorry for not noticing this earlier.

::: src/photos-done-notification.c
@@ +155,2 @@
                                   photos_done_notification_edit_undo_process,
+                                  self);

The base_item_process_async call will always be immediately cancelled because ...

@@ +158,1 @@
   photos_done_notification_destroy (self);

... this will call gtk_widget_destroy, which in turn will call the dispose vfunc and cancel the GCancellable.

One option is to gtk_widget_hide the notification here, and only call photos_done_notification_destroy once everything is done. If we do that then we must be careful to call it during the error paths too.

Another option, probably a better one, would be to turn this into an action. Let's say app.edit-undo that takes the URN/ID of the BaseItem as a string parameter. Then one of the global-ish classes (eg., PhotosApplication) can handle it. That will decouple the life time of the notification from that of the asynchronous operation.
Comment 99 Debarshi Ray 2016-06-18 10:05:41 UTC
Review of attachment 326097 [details] [review]:

Turning this whole operation into a GAction might be a better option. See attachment 326096 [details] [review]
Comment 100 Debarshi Ray 2016-06-18 10:30:49 UTC
Review of attachment 324489 [details] [review]:

::: src/photos-tracker-controller.c
@@ +172,3 @@
   photos_item_manager_add_item (PHOTOS_ITEM_MANAGER (priv->item_mngr), cursor);
   tracker_sparql_cursor_next_async (cursor,
+                                    self->priv->cursor_cancellable,

This does subtly change the logic, doesn't it?

Maybe we need a chained GCancellable that can (a) be directly cancelled, and (b) be cancelled as a result of cancelling another GCancellable. Few months ago I was asking on IRC for some prior art regarding this, but even though pbor said that this is a valid approach, I couldn't find any code samples. Shouldn't be too hard to implement it as a GCancellable sub-class, though.

@@ +197,2 @@
   tracker_sparql_cursor_next_async (cursor,
+                                    self->priv->cursor_cancellable,

Same here.
Comment 101 Debarshi Ray 2016-07-14 09:12:41 UTC
Created attachment 331470 [details] [review]
application, done-notification: Use a GAction to handle the revert
Comment 102 Debarshi Ray 2016-07-21 17:48:35 UTC
Created attachment 331900 [details] [review]
done-notification: Remove unnecessary references
Comment 103 Debarshi Ray 2016-07-21 17:49:20 UTC
Created attachment 331901 [details] [review]
application, done-notification: Use a GAction to handle the revert
Comment 104 Debarshi Ray 2016-12-01 09:17:13 UTC
Created attachment 341124 [details] [review]
tracker-controller: Don't use g_cancellable_reset
Comment 105 Debarshi Ray 2016-12-01 09:18:28 UTC
Created attachment 341125 [details] [review]
tracker-controller: Handle tracker_sparql_cursor_next_finish errors
Comment 106 GNOME Infrastructure Team 2018-01-23 09:59:13 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/gnome-photos/issues/43.