-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix #12203: return NULL after flb_worker_context_create failure in flb_log_create #12274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1001,6 +1001,25 @@ struct flb_log_metrics *flb_log_metrics_create() | |
| return metrics; | ||
| } | ||
|
|
||
| /* | ||
| * Release everything flb_log_create() has set up so far, for the failure | ||
| * paths that run after the channel manager pipe exists but before the | ||
| * collector thread is started. flb_log_destroy() cannot be used there: it | ||
| * joins log->tid and dereferences log->worker, neither of which is valid | ||
| * yet. | ||
| */ | ||
| static void log_create_cleanup(struct flb_log *log, struct flb_config *config) | ||
| { | ||
| flb_log_metrics_destroy(log->metrics); | ||
| flb_pipe_destroy(log->ch_mng); | ||
| log_close_sink(log); | ||
| pthread_mutex_destroy(&log->queue_mutex); | ||
| pthread_mutex_destroy(&log->pipeline_queue.mutex); | ||
| mk_event_loop_destroy(log->evl); | ||
| flb_free(log); | ||
| config->log = NULL; | ||
| } | ||
|
|
||
| struct flb_log *flb_log_create(struct flb_config *config, int type, | ||
| int level, char *out) | ||
| { | ||
|
|
@@ -1063,19 +1082,15 @@ struct flb_log *flb_log_create(struct flb_config *config, int type, | |
|
|
||
| if (ret == -1) { | ||
| fprintf(stderr, "[log] could not register event\n"); | ||
| mk_event_loop_destroy(log->evl); | ||
| flb_free(log); | ||
| config->log = NULL; | ||
| log_create_cleanup(log, config); | ||
| return NULL; | ||
| } | ||
|
|
||
| /* Create metrics */ | ||
| log->metrics = flb_log_metrics_create(); | ||
| if (log->metrics == NULL) { | ||
| fprintf(stderr, "[log] could not create log metrics\n"); | ||
| mk_event_loop_destroy(log->evl); | ||
| flb_free(log); | ||
| config->log = NULL; | ||
| log_create_cleanup(log, config); | ||
| return NULL; | ||
| } | ||
|
|
||
|
|
@@ -1087,9 +1102,8 @@ struct flb_log *flb_log_create(struct flb_config *config, int type, | |
| worker = flb_worker_context_create(NULL, NULL, config); | ||
| if (!worker) { | ||
| flb_errno(); | ||
| mk_event_loop_destroy(log->evl); | ||
| flb_free(log); | ||
| config->log = NULL; | ||
| log_create_cleanup(log, config); | ||
| return NULL; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ @MsfPablo We need to release resources on exceptions. |
||
| } | ||
|
|
||
| /* Set the worker context global */ | ||
|
|
@@ -1099,9 +1113,7 @@ struct flb_log *flb_log_create(struct flb_config *config, int type, | |
| ret = flb_log_worker_init(worker); | ||
| if (ret == -1) { | ||
| flb_errno(); | ||
| mk_event_loop_destroy(log->evl); | ||
| flb_free(log); | ||
| config->log = NULL; | ||
| log_create_cleanup(log, config); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Clear
Suggested fix ret = flb_log_worker_init(worker);
if (ret == -1) {
flb_errno();
+ FLB_TLS_SET(flb_worker_ctx, NULL);
log_create_cleanup(log, config);
flb_free(worker);
return NULL;
}🤖 Prompt for AI Agents |
||
| flb_free(worker); | ||
| return NULL; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Extend cleanup to every pre-thread failure path.
log_create_cleanup()is not used whenflb_pipe_create()fails or whenflb_worker_create()fails. The first path can leaklog->out_fdand both queue mutexes. The second path can leak metrics, the channel-manager pipe, the sink, the worker cache,pth_mutex, andpth_cond. It also freeslog->workerwithout the cache cleanup used byflb_log_destroy(). Sinceflb_config_exit()skipsflb_log_destroy()afterconfig->logis cleared, add stage-aware cleanup for both exits.🤖 Prompt for AI Agents