From: Jorge Gea Date: Thu, 17 Mar 2022 10:27:39 +0000 (+0100) Subject: meta: Add complete packets in debug for protocol error. Cancel backend in those situa... X-Git-Tag: Beta-15.0.0~621 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c81dd79d1d80c9d39584cbe213f6c7c87b43546c;p=thirdparty%2Fbacula.git meta: Add complete packets in debug for protocol error. Cancel backend in those situations --- diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp index 4fcf619be..2888d7c7b 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp +++ b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp @@ -1373,6 +1373,8 @@ bRC METAPLUGIN::perform_read_data(bpContext *ctx, struct io_pkt *io) if (rc < 0){ io->status = rc; io->io_errno = EIO; + // We should get here only with Protocol errors, so we should terminate backends, as this is always fatal + cancel_all_backends(ctx); return bRC_Error; } io->status = rc; @@ -1531,7 +1533,8 @@ bRC METAPLUGIN::perform_read_acl(bpContext *ctx) if (!backend.ctx->read_ack(ctx)){ /* should get EOD */ DMSG0(ctx, DERROR, "Protocol error, should get EOD.\n"); - backend.ctx->terminate(ctx); + // In protocol error situations, the communication has no chance to continue, so we need to kill the backend + cancel_all_backends(ctx); return bRC_Error; } @@ -1568,7 +1571,8 @@ bRC METAPLUGIN::perform_read_xattr(bpContext *ctx) if (!backend.ctx->read_ack(ctx)){ /* should get EOD */ DMSG0(ctx, DERROR, "Protocol error, should get EOD.\n"); - backend.ctx->terminate(ctx); + // In protocol error situations, the communication has no chance to continue, so we need to kill the backend + cancel_all_backends(ctx); return bRC_Error; } readxattr = true; @@ -1599,7 +1603,8 @@ bRC METAPLUGIN::perform_read_metadata_info(bpContext *ctx, metadata_type type, s if (!backend.ctx->read_ack(ctx)){ /* should get EOD */ DMSG0(ctx, DERROR, "Protocol error, should get EOD.\n"); - backend.ctx->terminate(ctx); + // In protocol error situations, the communication has no chance to continue, so we need to kill the backend + cancel_all_backends(ctx); return bRC_Error; } @@ -1816,7 +1821,8 @@ bRC METAPLUGIN::perform_read_metacommands(bpContext *ctx) /* error in protocol */ DMSG(ctx, DERROR, "Protocol error, got unknown command: %s\n", cmd.c_str()); JMSG(ctx, M_FATAL, "Protocol error, got unknown command: %s\n", cmd.c_str()); - backend.ctx->terminate(ctx); + // In protocol error situations, the communication has no chance to continue, so we need to kill the backend + cancel_all_backends(ctx); return bRC_Error; } else { if (backend.ctx->is_fatal()){ @@ -2078,7 +2084,7 @@ bRC METAPLUGIN::perform_read_pluginobject(bpContext *ctx, struct save_pkt *sp) /* error in protocol */ DMSG(ctx, DERROR, "Protocol error, got unknown command: %s\n", cmd.c_str()); JMSG(ctx, M_FATAL, "Protocol error, got unknown command: %s\n", cmd.c_str()); - backend.ctx->terminate(ctx); + cancel_all_backends(ctx); return bRC_Error; } else { if (backend.ctx->is_fatal()){ @@ -2463,7 +2469,8 @@ bRC METAPLUGIN::startBackupFile(bpContext *ctx, struct save_pkt *sp) if (reqparams > 0) { DMSG0(ctx, DERROR, "Protocol error, not enough file attributes from backend.\n"); JMSG0(ctx, M_FATAL, "Protocol error, not enough file attributes from backend.\n"); - backend.ctx->terminate(ctx); + // In protocol error situations, the communication has no chance to continue, so we need to kill the backend + cancel_all_backends(ctx); return bRC_Error; } diff --git a/bacula/src/plugins/fd/pluginlib/ptcomm.cpp b/bacula/src/plugins/fd/pluginlib/ptcomm.cpp index 979613722..174e70e15 100644 --- a/bacula/src/plugins/fd/pluginlib/ptcomm.cpp +++ b/bacula/src/plugins/fd/pluginlib/ptcomm.cpp @@ -127,6 +127,7 @@ void PTCOMM::terminate(bpContext *ctx) if (worker_pid) { /* terminate the backend */ + DMSG(ctx, DINFO, "Killing backend with PID=%d\n", worker_pid); kill(worker_pid, SIGTERM); } @@ -346,7 +347,6 @@ int32_t PTCOMM::recvbackend_header(bpContext *ctx, char *cmd, bool any) DMSG0(ctx, DERROR, "PTCOMM cannot get packet header from backend.\n"); JMSG0(ctx, M_FATAL, "PTCOMM cannot get packet header from backend.\n"); f_eod = f_error = f_fatal = true; - terminate(ctx); return -1; } @@ -374,9 +374,8 @@ int32_t PTCOMM::recvbackend_header(bpContext *ctx, char *cmd, bool any) if (header.status == 'C' || header.status == 'D') { if (!any) { if (header.status != *cmd) { - DMSG2(ctx, DERROR, "Protocol error. Expected packet: %c got: %c\n", *cmd, header.status); - JMSG2(ctx, M_FATAL, "Protocol error. Expected packet: %c got: %c\n", *cmd, header.status); - terminate(ctx); + DMSG3(ctx, DERROR, "Protocol error. Expected packet: %c got: %c:%s\n", *cmd, header.status, header.length); + JMSG3(ctx, M_FATAL, "Protocol error. Expected packet: %c got: %c:%s\n", *cmd, header.status, header.length); return -1; } } else { @@ -473,7 +472,6 @@ int32_t PTCOMM::recvbackend_header(bpContext *ctx, char *cmd, bool any) default: DMSG2(ctx, DERROR, "Protocol error. Unknown packet: %c:%s\n", header.status, header.length); JMSG2(ctx, M_FATAL, "Protocol error. Unknown packet: %c:%s\n", header.status, header.length); - terminate(ctx); return -1; } }