]> source.dussan.org Git - rspamd.git/commitdiff
Fix writing reply to a client.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 18 Sep 2014 16:50:40 +0000 (17:50 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 18 Sep 2014 16:50:40 +0000 (17:50 +0100)
Issue: #94
Reported by: @jpastuszek

src/libserver/protocol.c
src/libserver/task.c
src/libserver/task.h
src/worker.c

index ac41dca0c7feb00343e962ca03e63f8df9f7f9e6..26efc9b7cbbf3797e4b010135925472cccf253ed 100644 (file)
@@ -855,7 +855,7 @@ rspamd_protocol_write_reply (struct rspamd_task *task)
        }
        msg->date = time (NULL);
 
-       task->state = CLOSING_CONNECTION;
+       task->state = WRITING_REPLY;
 
        debug_task ("writing reply to client");
        if (task->error_code != 0) {
index 860bb2b0394c962c5a88a5a58946071ece87c1b8..8eb0c7932306d85a4dfda91a3007eb3ecf7fb236 100644 (file)
@@ -335,6 +335,7 @@ rspamd_task_process (struct rspamd_task *task,
                        /* Call write_socket to write reply and exit */
                        task->state = WRITE_REPLY;
                }
+               task->s->wanna_die = TRUE;
        }
        else {
                rspamd_lua_call_pre_filters (task);
index bf14d21747d3f7504b82676c102bc6b7b6319a04..2fd634e54357f49febcb7780da6355d815a2280b 100644 (file)
@@ -69,6 +69,7 @@ struct rspamd_task {
                WAIT_FILTER,
                WAIT_POST_FILTER,
                WRITE_REPLY,
+               WRITING_REPLY,
                CLOSING_CONNECTION
        } state;                                                    /**< current session state                                                  */
        enum rspamd_command cmd;                                    /**< command                                                                                */
index c0e8cacd299119928c0440d9c4a9e47f82eb7092..26e59ace2bef2b08c9459a95ccbe8100d520bcc9 100644 (file)
@@ -141,7 +141,7 @@ rspamd_worker_error_handler (struct rspamd_http_connection *conn, GError *err)
 
        msg_info ("abnormally closing connection from: %s, error: %s",
                rspamd_inet_address_to_string (&task->client_addr), err->message);
-       if (task->state != CLOSING_CONNECTION) {
+       if (task->state != CLOSING_CONNECTION && task->state != WRITING_REPLY) {
                /* We still need to write a reply */
                task->error_code = err->code;
                task->last_error =
@@ -166,7 +166,7 @@ rspamd_worker_finish_handler (struct rspamd_http_connection *conn,
                        rspamd_inet_address_to_string (&task->client_addr));
                destroy_session (task->s);
        }
-       else {
+       else if (task->state != WRITING_REPLY) {
                /*
                 * If all filters have finished their tasks, this function will trigger
                 * writing a reply.
@@ -174,6 +174,12 @@ rspamd_worker_finish_handler (struct rspamd_http_connection *conn,
                task->s->wanna_die = TRUE;
                check_session_pending (task->s);
        }
+       else {
+               /*
+                * We are going to write a reply to a client
+                */
+               task->state = CLOSING_CONNECTION;
+       }
 
        return 0;
 }