core: Error handling of upload file writing
authorGrzegorz Grabowski <grzegorz.grabowski@comarch.com>
Thu, 27 Oct 2011 12:56:00 +0000 (14:56 +0200)
committerJens Georg <mail@jensge.org>
Mon, 21 Nov 2011 09:31:53 +0000 (10:31 +0100)
If stream.write_all method threw an exception Rygel crashed.
It happened because on_got_body and on_got_chunk signals came after
HTTPPost object transitioned to finished state.
The fix disconnects from these signals after file writing errors occurs
since there is no recovery from such situation which in real
happens only when there is no disk space or max file size is limited.

src/rygel/rygel-http-post.vala
src/rygel/rygel-http-request.vala

index 887cec4..5a3a5f0 100644 (file)
@@ -204,7 +204,9 @@ internal class Rygel.HTTPPost : HTTPRequest {
         try {
             this.stream.write_all (chunk.data, null, this.cancellable);
         } catch (Error error) {
-            this.handle_error (error);
+            this.disconnect_message_signals ();
+            this.handle_error (
+                new HTTPRequestError.INTERNAL_SERVER_ERROR (error.message));
             this.handle_continue ();
         }
     }
@@ -217,5 +219,11 @@ internal class Rygel.HTTPPost : HTTPRequest {
         var queue = ItemRemovalQueue.get_default ();
         yield queue.remove_now (this.item, null);
     }
+
+    private void disconnect_message_signals () {
+        this.msg.got_body.disconnect (this.on_got_body);
+        this.msg.got_chunk.disconnect (this.on_got_chunk);
+    }
+
 }
 
index 1a79065..93ef830 100644 (file)
@@ -26,7 +26,8 @@
 internal errordomain Rygel.HTTPRequestError {
     UNACCEPTABLE = Soup.KnownStatusCode.NOT_ACCEPTABLE,
     BAD_REQUEST = Soup.KnownStatusCode.BAD_REQUEST,
-    NOT_FOUND = Soup.KnownStatusCode.NOT_FOUND
+    NOT_FOUND = Soup.KnownStatusCode.NOT_FOUND,
+    INTERNAL_SERVER_ERROR = Soup.KnownStatusCode.INTERNAL_SERVER_ERROR
 }
 
 /**