]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix more issues with scripts processing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 7 May 2016 11:36:50 +0000 (12:36 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 7 May 2016 11:36:50 +0000 (12:36 +0100)
src/rspamd_proxy.c

index 076eed5ede1ca255a2bd4f9ce3563fc3185d5fbc..dc926066ce46e756e301c761c721679e769a97a4 100644 (file)
@@ -494,6 +494,7 @@ init_rspamd_proxy (struct rspamd_config *cfg)
        ctx->rotate_tm = DEFAULT_ROTATION_TIME;
        ctx->cfg = cfg;
        ctx->lua_state = cfg->lua_state;
+       ctx->cmp_refs = g_array_new (FALSE, FALSE, sizeof (gint));
 
        rspamd_rcl_register_worker_option (cfg,
                        type,
@@ -555,7 +556,7 @@ init_rspamd_proxy (struct rspamd_config *cfg)
 static void
 proxy_backend_close_connection (struct rspamd_proxy_backend_connection *conn)
 {
-       if (conn) {
+       if (conn && !(conn->flags & RSPAMD_BACKEND_CLOSED)) {
                if (conn->backend_conn) {
                        rspamd_http_connection_reset (conn->backend_conn);
                        rspamd_http_connection_unref (conn->backend_conn);
@@ -644,6 +645,11 @@ proxy_call_cmp_script (struct rspamd_proxy_session *session, gint cbref)
                ucl_object_push_lua (L, session->master_conn->results, true);
                lua_settable (L, -3);
        }
+       else {
+               lua_pushstring (L, "master");
+               lua_pushstring (L, "no results");
+               lua_settable (L, -3);
+       }
 
        for (i = 0; i < session->mirror_conns->len; i ++) {
                conn = g_ptr_array_index (session->mirror_conns, i);
@@ -653,6 +659,11 @@ proxy_call_cmp_script (struct rspamd_proxy_session *session, gint cbref)
                        ucl_object_push_lua (L, conn->results, true);
                        lua_settable (L, -3);
                }
+               else {
+                       lua_pushstring (L, conn->name);
+                       lua_pushstring (L, "no results");
+                       lua_settable (L, -3);
+               }
        }
 
        if (lua_pcall (L, 1, 0, err_idx) != 0) {
@@ -673,6 +684,11 @@ proxy_session_dtor (struct rspamd_proxy_session *session)
        gint cbref;
        struct rspamd_proxy_backend_connection *conn;
 
+       for (i = 0; i < session->ctx->cmp_refs->len; i ++) {
+               cbref = g_array_index (session->ctx->cmp_refs, gint, i);
+               proxy_call_cmp_script (session, cbref);
+       }
+
        if (session->master_conn) {
                proxy_backend_close_connection (session->master_conn);
        }
@@ -686,11 +702,6 @@ proxy_session_dtor (struct rspamd_proxy_session *session)
                rspamd_http_connection_unref (session->client_conn);
        }
 
-       for (i = 0; i < session->ctx->cmp_refs->len; i ++) {
-               cbref = g_array_index (session->ctx->cmp_refs, gint, i);
-               proxy_call_cmp_script (session, cbref);
-       }
-
        for (i = 0; i < session->mirror_conns->len; i ++) {
                conn = g_ptr_array_index (session->mirror_conns, i);
 
@@ -962,7 +973,6 @@ proxy_client_error_handler (struct rspamd_http_connection *conn, GError *err)
                rspamd_inet_address_to_string (session->client_addr), err->message);
        /* Terminate session immediately */
        proxy_backend_close_connection (session->master_conn);
-       session->master_conn = NULL;
        REF_RELEASE (session);
 }
 
@@ -1048,7 +1058,6 @@ proxy_client_finish_handler (struct rspamd_http_connection *conn,
        }
        else {
                proxy_backend_close_connection (session->master_conn);
-               session->master_conn = NULL;
                REF_RELEASE (session);
        }
 
@@ -1142,7 +1151,6 @@ start_rspamd_proxy (struct rspamd_worker *worker)
        ctx->resolver = dns_resolver_init (worker->srv->logger,
                        ctx->ev_base,
                        worker->srv->cfg);
-       ctx->cmp_refs = g_array_new (FALSE, FALSE, sizeof (gint));
        double_to_tv (ctx->timeout, &ctx->io_tv);
        rspamd_map_watch (worker->srv->cfg, ctx->ev_base, ctx->resolver);