]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix fuzzystat control replies
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 16 Jan 2026 13:25:04 +0000 (13:25 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 16 Jan 2026 13:25:04 +0000 (13:25 +0000)
src/fuzzy_storage.c
src/libserver/rspamd_control.c

index 70e274e1f3444cc219811fbdae276940aca7ff2c..801a9dfda568eaee2e18a45efa642eca3a2869bf 100644 (file)
@@ -3474,11 +3474,16 @@ rspamd_fuzzy_storage_stat(struct rspamd_main *rspamd_main,
                                          strerror(errno));
        }
        else {
+               const char *backend_id;
+
                rep.reply.fuzzy_stat.status = 0;
 
-               memcpy(rep.reply.fuzzy_stat.storage_id,
-                          rspamd_fuzzy_backend_id(ctx->backend),
-                          sizeof(rep.reply.fuzzy_stat.storage_id));
+               backend_id = rspamd_fuzzy_backend_id(ctx->backend);
+               if (backend_id) {
+                       memcpy(rep.reply.fuzzy_stat.storage_id,
+                                  backend_id,
+                                  sizeof(rep.reply.fuzzy_stat.storage_id));
+               }
 
                obj = rspamd_fuzzy_stat_to_ucl(ctx, TRUE);
                emit_subr = ucl_object_emit_fd_funcs(outfd);
index f730aaf9ef10c2d39315c36007e7a812794c9458..17e53abc34c76370034d957f24cf62a226694a35 100644 (file)
@@ -39,7 +39,6 @@
                                                                                                                         __VA_ARGS__)
 
 static ev_tstamp io_timeout = 30.0;
-static ev_tstamp worker_io_timeout = 0.5;
 
 struct rspamd_control_session;
 
@@ -462,11 +461,27 @@ rspamd_control_reply_handler(EV_P_ ev_io *w, int revents)
        struct rspamd_control_reply rep;
        struct rspamd_control_reply_elt *elt;
        struct rspamd_main *rspamd_main = wrk->srv;
+       struct msghdr msg;
+       struct iovec iov;
+       unsigned char fdspace[CMSG_SPACE(sizeof(int))];
+       int rfd;
        gssize r;
        khiter_t k;
 
        for (;;) {
-               r = read(w->fd, &rep, sizeof(rep));
+               rfd = -1;
+               memset(&msg, 0, sizeof(msg));
+               msg.msg_control = fdspace;
+               msg.msg_controllen = sizeof(fdspace);
+               iov.iov_base = &rep;
+               iov.iov_len = sizeof(rep);
+               msg.msg_iov = &iov;
+               msg.msg_iovlen = 1;
+               r = recvmsg(w->fd, &msg, 0);
+
+               if (r > 0 && msg.msg_controllen >= CMSG_LEN(sizeof(int))) {
+                       rfd = *(int *) CMSG_DATA(CMSG_FIRSTHDR(&msg));
+               }
 
                if (r == -1) {
                        if (errno == EAGAIN || errno == EWOULDBLOCK) {
@@ -482,12 +497,18 @@ rspamd_control_reply_handler(EV_P_ ev_io *w, int revents)
                        /* Connection closed */
                        msg_debug_control("control pipe closed for worker %P", wrk->pid);
                        ev_io_stop(EV_A_ w);
+                       if (rfd != -1) {
+                               close(rfd);
+                       }
                        break;
                }
 
                if (r != (gssize) sizeof(rep)) {
                        msg_err_main("incomplete control reply from worker %P: %d != %d",
                                                 wrk->pid, (int) r, (int) sizeof(rep));
+                       if (rfd != -1) {
+                               close(rfd);
+                       }
                        continue;
                }
 
@@ -497,6 +518,9 @@ rspamd_control_reply_handler(EV_P_ ev_io *w, int revents)
                        msg_warn_main("received control reply for unknown request id %" G_GUINT64_FORMAT
                                                  " from worker %P",
                                                  rep.id, wrk->pid);
+                       if (rfd != -1) {
+                               close(rfd);
+                       }
                        continue;
                }
 
@@ -506,6 +530,10 @@ rspamd_control_reply_handler(EV_P_ ev_io *w, int revents)
                msg_debug_control("received reply for command %d id %" G_GUINT64_FORMAT " from worker %P(%s)",
                                                  (int) rep.type, rep.id, wrk->pid, g_quark_to_string(wrk->type));
 
+               if (rfd != -1) {
+                       elt->attached_fd = rfd;
+               }
+
                /* Copy reply to element and call handler */
                memcpy(&elt->reply, &rep, sizeof(rep));
                if (elt->handler) {