Skip to content

Commit e3bffa3

Browse files
committed
fix: include incoming message size when checking against batch size
1 parent 6efdb16 commit e3bffa3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/cpp-statsd-client/UDPSender.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ inline void UDPSender::queueMessage(const std::string& message) noexcept {
246246
// We aquire a lock but only if we actually need to (i.e. there is a thread also accessing the queue)
247247
auto batchingLock =
248248
m_batchingThread.joinable() ? std::unique_lock<std::mutex>(m_batchingMutex) : std::unique_lock<std::mutex>();
249-
// Either we don't have a place to batch our message or we exceeded the batch size, so make a new batch
250-
if (m_batchingMessageQueue.empty() || m_batchingMessageQueue.back().length() > m_batchsize) {
249+
// Either we don't have a place to batch our message or we are about to exceed the batch size, so make a new batch
250+
if (m_batchingMessageQueue.empty() || m_batchingMessageQueue.back().size() + message.size() > m_batchsize) {
251251
m_batchingMessageQueue.emplace_back();
252252
m_batchingMessageQueue.back().reserve(m_batchsize + 256);
253253
} // When there is already a batch open we need a separator when its not empty

0 commit comments

Comments
 (0)