Skip to content

Commit

Permalink
reload: bin: Handle hot-reloading is aborted case
Browse files Browse the repository at this point in the history
In our hot-reloading context handling, there is a possibility not to
able to handle hot-reloading correctly.
For this case, we should treat as error and halt the process.

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Oct 31, 2023
1 parent 0ae1dba commit dded3c9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/fluent-bit/flb_reload.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#define FLB_RELOAD_IDLE 0
#define FLB_RELOAD_IN_PROGRESS 1
#define FLB_RELOAD_ABORTED 2

int flb_reload_property_check_all(struct flb_config *config);
int flb_reload_reconstruct_cf(struct flb_cf *src_cf, struct flb_cf *dest_cf);
Expand Down
17 changes: 12 additions & 5 deletions src/flb_reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,19 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts)

ret = flb_start(new_ctx);

/* Store the new value of hot reloading times into the new context */
if (ret == 0) {
new_config->hot_reloaded_count = reloaded_count;
flb_debug("[reload] hot reloaded %d time(s)", reloaded_count);
new_config->hot_reloading = FLB_FALSE;
if (ret != 0) {
flb_stop(new_ctx);
flb_destroy(new_ctx);

flb_error("[reload] loaded configuration contains error(s). Reloading is aborted");

return -1;
}

/* Store the new value of hot reloading times into the new context */
new_config->hot_reloaded_count = reloaded_count;
flb_debug("[reload] hot reloaded %d time(s)", reloaded_count);
new_config->hot_reloading = FLB_FALSE;

return 0;
}
24 changes: 18 additions & 6 deletions src/fluent-bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1394,16 +1394,23 @@ int flb_main(int argc, char **argv)
#endif
if (flb_bin_restarting == FLB_RELOAD_IN_PROGRESS) {
/* reload by using same config files/path */
flb_reload(ctx, cf_opts);
ctx = flb_context_get();
flb_bin_restarting = FLB_RELOAD_IDLE;
ret = flb_reload(ctx, cf_opts);
if (ret == 0) {
ctx = flb_context_get();
flb_bin_restarting = FLB_RELOAD_IDLE;
}
else {
flb_bin_restarting = FLB_RELOAD_ABORTED;
}
}
}

if (exit_signal) {
flb_signal_exit(exit_signal);
}
ret = ctx->config->exit_status_code;
if (flb_bin_restarting != FLB_RELOAD_ABORTED) {
ret = ctx->config->exit_status_code;
}

cf_opts = flb_cf_context_get();

Expand All @@ -1425,8 +1432,13 @@ int flb_main(int argc, char **argv)
}
#endif

flb_stop(ctx);
flb_destroy(ctx);
if (flb_bin_restarting == FLB_RELOAD_ABORTED) {
fprintf(stderr, "reloading is aborted and exit\n");
}
else {
flb_stop(ctx);
flb_destroy(ctx);
}

return ret;
}
Expand Down

0 comments on commit dded3c9

Please sign in to comment.