Skip to content

Commit

Permalink
engine: print and track scheduled timer coroutines on shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Pettit <[email protected]>
  • Loading branch information
PettitWesley committed Nov 29, 2023
1 parent 6132ad8 commit 7d81de8
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions src/flb_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,37 @@ static inline int handle_output_events(flb_pipefd_t fd,
return result;
}

static int flb_running_count(struct flb_config *config)
{
int tasks = 0, timers = 0, n = 0;
struct mk_list *head;
struct mk_list *tmp;
struct flb_output_instance *o_ins;

mk_list_foreach_safe(head, tmp, &config->outputs) {
o_ins = mk_list_entry(head, struct flb_output_instance, _head);
n = flb_output_timer_coros_size(o_ins);
timers = timers + n;
}

tasks = flb_task_running_count(config);
return tasks + timers;
}

static void flb_running_print(struct flb_config *config)
{
struct mk_list *head;
struct mk_list *tmp;
struct flb_output_instance *o_ins;

flb_task_running_print(config);

mk_list_foreach_safe(head, tmp, &config->outputs) {
o_ins = mk_list_entry(head, struct flb_output_instance, _head);
flb_output_timer_coros_print(o_ins);
}
}

static inline int flb_engine_manager(flb_pipefd_t fd, struct flb_config *config)
{
int bytes;
Expand Down Expand Up @@ -651,6 +682,7 @@ int sb_segregate_chunks(struct flb_config *config)
int flb_engine_start(struct flb_config *config)
{
int ret;
int count;
uint64_t ts;
char tmp[16];
int rb_flush_flag;
Expand Down Expand Up @@ -968,19 +1000,19 @@ int flb_engine_start(struct flb_config *config)
* If grace period is set to -1, keep trying to shut down until all
* tasks and retries get flushed.
*/
ret = flb_task_running_count(config);
if (ret > 0 && (config->grace_count < config->grace || config->grace == -1)) {
count = flb_running_count(config);
if (count > 0 && (config->grace_count < config->grace || config->grace == -1)) {
if (config->grace_count == 1) {
flb_task_running_print(config);
flb_running_print(config);
}
flb_engine_exit(config);
}
else {
if (ret > 0) {
flb_task_running_print(config);
if (count > 0) {
flb_running_print(config);
}
flb_info("[engine] service has stopped (%i pending tasks)",
ret);
flb_info("[engine] service has stopped (%d pending tasks)",
count);
ret = config->exit_status_code;
flb_engine_shutdown(config);
config = NULL;
Expand Down

0 comments on commit 7d81de8

Please sign in to comment.