Skip to content

Commit 34fc9a6

Browse files
falucocodebot
authored andcommitted
Fix race condition in io timer source when passing the FD to read_time
F
1 parent 8b09f26 commit 34fc9a6

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

include/srsran/support/io/io_broker.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ class io_broker
7979
return ret;
8080
}
8181

82-
/// Returns the file descriptor value held by this subscriber.
83-
int value() const { return fd; }
84-
8582
private:
8683
bool reset_impl(std::promise<bool>* complete_notifier = nullptr)
8784
{

include/srsran/support/io/io_timer_source.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class io_timer_source
4343
void create_subscriber();
4444
void destroy_subscriber();
4545

46-
void read_time();
46+
void read_time(int raw_fd);
4747

4848
void update_state(bool start);
4949
bool handle_state_update(bool defer_stop);

lib/support/network/io_timer_source.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ void io_timer_source::create_subscriber()
8888
}
8989

9090
logger.info("Starting IO timer ticking source...");
91-
io_sub = broker.register_fd(create_timer_fd(tick_period), tick_exec, [this]() { read_time(); });
92-
report_fatal_error_if_not(io_sub.value() > 0, "Failed to create timer source");
91+
auto fd = create_timer_fd(tick_period);
92+
int raw_fd = fd.value();
93+
io_sub = broker.register_fd(std::move(fd), tick_exec, [this, raw_fd]() { read_time(raw_fd); });
94+
report_fatal_error_if_not(io_sub.registered(), "Failed to create timer source");
9395
}
9496

9597
void io_timer_source::destroy_subscriber()
@@ -146,7 +148,7 @@ bool io_timer_source::handle_state_update(bool defer_stop)
146148
return sub_destroyed;
147149
}
148150

149-
void io_timer_source::read_time()
151+
void io_timer_source::read_time(int raw_fd)
150152
{
151153
// Note: Called inside the ticking executor.
152154

@@ -159,7 +161,7 @@ void io_timer_source::read_time()
159161
}
160162

161163
uint64_t nof_expirations = 0;
162-
int n = ::read(io_sub.value(), &nof_expirations, sizeof(nof_expirations));
164+
int n = ::read(raw_fd, &nof_expirations, sizeof(nof_expirations));
163165
if (n < 0) {
164166
logger.error("Failed to read timerfd (errno={})", ::strerror(errno));
165167
return;

0 commit comments

Comments
 (0)