Interrupted image upload causes mongoose interface toalways return "500 Failed to queue command"
diff mbox series

Message ID c30a554b-00b0-4e92-b19b-14542779260f@googlegroups.com
State New
Headers show
Series
  • Interrupted image upload causes mongoose interface toalways return "500 Failed to queue command"
Related show

Commit Message

Simon Wamelink May 15, 2019, 9:29 a.m. UTC
Hi,

If a file upload is interrupted before completing the mongoose interface 
will always send 500 errors on subsequent requests. I've traced this issue 
back to fus->fd not being closed when the connection is interrupted. Any 
calls to ipc_inst_start_ext() after that will fail since the previous file 
descriptor is not closed. 

I've made an workaround for this issue but think this could be done better.

Kind regards,

Simon Wamelink


 
                break;

Patch
diff mbox series

diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
index 68ff675..503fcb1 100644
--- a/mongoose/mongoose_interface.c
+++ b/mongoose/mongoose_interface.c
@@ -57,6 +57,7 @@  struct file_upload_state {
 
 static struct mg_serve_http_opts s_http_server_opts;
 static void upload_handler(struct mg_connection *nc, int ev, void *p);
+static int fus_fd = -1;
 
 /*
  * These functions are for V2 of the protocol
@@ -389,9 +390,16 @@  static void upload_handler(struct mg_connection *nc, 
int ev, void *p)
                if (fus->fd < 0) {
                        mg_http_send_error(nc, 500, "Failed to queue 
command");
                        free(fus);
+
+                       if (fus_fd > 0) {
+                               ipc_end(fus_fd);
+                               fus_fd = -1;
+                       }
                        break;
                }
 
+               fus_fd = fus->fd;
+
                mp->user_data = fus;