Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/flb_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ struct flb_sched *flb_sched_create(struct flb_config *config,

sched->config = config;
sched->evl = evl;
sched->ch_events[0] = -1;
sched->ch_events[1] = -1;
MK_EVENT_ZERO(&sched->event);

/* Initialize lists */
mk_list_init(&sched->requests);
Expand Down Expand Up @@ -791,7 +794,7 @@ struct flb_sched *flb_sched_create(struct flb_config *config,
ret = mk_event_channel_create(sched->evl,
&sched->ch_events[0],
&sched->ch_events[1],
sched);
&sched->event);
if (ret == -1) {
flb_sched_destroy(sched);
return NULL;
Expand Down Expand Up @@ -849,6 +852,15 @@ int flb_sched_destroy(struct flb_sched *sched)
c++;
}

if (sched->ch_events[0] != -1) {
mk_event_channel_destroy(sched->evl,
sched->ch_events[0],
sched->ch_events[1],
&sched->event);
sched->ch_events[0] = -1;
sched->ch_events[1] = -1;
}

flb_free(sched);
return c;
}
Expand Down
1 change: 1 addition & 0 deletions tests/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(UNIT_TESTS_FILES
flb_event_loop.c
ring_buffer.c
regex.c
scheduler.c
parser_json.c
parser_ltsv.c
parser_regex.c
Expand Down
110 changes: 110 additions & 0 deletions tests/internal/scheduler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015-2026 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <fluent-bit/flb_config.h>
#include <fluent-bit/flb_pipe.h>
#include <fluent-bit/flb_scheduler.h>

#include "flb_tests_internal.h"

static void test_scheduler_event_channel_cleanup(void)
{
int ret;
char data = '\0';
flb_pipefd_t read_fd[2];
flb_pipefd_t write_fd[2];
struct flb_sched *sched[2];
struct flb_config *config;
struct mk_event_loop *evl;
#ifdef FLB_SYSTEM_WINDOWS
WSADATA wsa_data;

ret = WSAStartup(MAKEWORD(2, 2), &wsa_data);
if (!TEST_CHECK(ret == 0)) {
return;
}
#endif

config = flb_config_init();
if (!TEST_CHECK(config != NULL)) {
goto socket_cleanup;
}

config->evl = mk_event_loop_create(8);
if (!TEST_CHECK(config->evl != NULL)) {
flb_config_exit(config);
goto socket_cleanup;
}

sched[0] = flb_sched_create(config, config->evl);
if (!TEST_CHECK(sched[0] != NULL)) {
flb_config_exit(config);
goto socket_cleanup;
}
config->sched = sched[0];

evl = mk_event_loop_create(8);
if (!TEST_CHECK(evl != NULL)) {
flb_config_exit(config);
goto socket_cleanup;
}

sched[1] = flb_sched_create(config, evl);
if (!TEST_CHECK(sched[1] != NULL)) {
mk_event_loop_destroy(evl);
flb_config_exit(config);
goto socket_cleanup;
}

read_fd[0] = sched[0]->ch_events[0];
write_fd[0] = sched[0]->ch_events[1];
read_fd[1] = sched[1]->ch_events[0];
write_fd[1] = sched[1]->ch_events[1];

flb_sched_destroy(sched[1]);
mk_event_loop_destroy(evl);

flb_sched_destroy(sched[0]);
config->sched = NULL;

ret = flb_pipe_w(write_fd[0], &data, sizeof(data));
TEST_CHECK(ret == -1);

ret = flb_pipe_r(read_fd[0], &data, sizeof(data));
TEST_CHECK(ret == -1);

ret = flb_pipe_w(write_fd[1], &data, sizeof(data));
TEST_CHECK(ret == -1);

ret = flb_pipe_r(read_fd[1], &data, sizeof(data));
TEST_CHECK(ret == -1);

flb_config_exit(config);

socket_cleanup:
(void) ret;
#ifdef FLB_SYSTEM_WINDOWS
WSACleanup();
#endif
}

TEST_LIST = {
{"event_channel_cleanup", test_scheduler_event_channel_cleanup},
{NULL, NULL}
};
Loading