Skip to content

Commit 53c6f56

Browse files
author
Pavel Siska
committed
ipfix: fix stuck flushing loop after TCP disconnect in LZ4 mode
In LZ4 compress mode, a failed send_packet() call in send_templates() left readSize non-zero, causing the next getWriteBuffer() in send_data() to return null and exit without clearing template buffers. Fix by adding CompressBuffer::getWriteBufferOrReset() which resets via shrinkTo(0) and retries once on null.
1 parent 6c8fc7e commit 53c6f56

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/plugins/output/ipfix/src/ipfix.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,10 +818,8 @@ void IPFIXExporter::send_data()
818818
* Loop ends when len = create_data_packet() is 0
819819
*/
820820
while (true) {
821-
pkt.data = packetDataBuffer.getWriteBuffer(mtu);
821+
pkt.data = packetDataBuffer.getWriteBufferOrReset(mtu);
822822
if (!pkt.data) {
823-
// this should never happen because packetDataBuffer
824-
// should already have enough allocated memory
825823
return;
826824
}
827825

@@ -1227,6 +1225,16 @@ int CompressBuffer::init(bool compress, size_t compressSize, size_t writeSize)
12271225
return 0;
12281226
}
12291227

1228+
uint8_t* CompressBuffer::getWriteBufferOrReset(size_t requiredSize)
1229+
{
1230+
uint8_t* buffer = getWriteBuffer(requiredSize);
1231+
if (buffer != nullptr) {
1232+
return buffer;
1233+
}
1234+
shrinkTo(0);
1235+
return getWriteBuffer(requiredSize);
1236+
}
1237+
12301238
uint8_t* CompressBuffer::getWriteBuffer(size_t requiredSize)
12311239
{
12321240
// the contents can happily fit into the buffer

src/plugins/output/ipfix/src/ipfix.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,17 @@ class CompressBuffer {
457457
*/
458458
uint8_t* getWriteBuffer(size_t requiredSize);
459459

460+
/**
461+
* @brief Attempts to get a write buffer, resetting internal state on failure and retrying once.
462+
*
463+
* This can happen in compress mode when a previous send failed without calling
464+
* compress(), leaving readSize non-zero and causing getWriteBuffer() to return null.
465+
*
466+
* @param requiredSize required size of the buffer
467+
* @return pointer to the buffer with the required size, null on failure
468+
*/
469+
uint8_t* getWriteBufferOrReset(size_t requiredSize);
470+
460471
/**
461472
* @brief compresses data written after last compress() call
462473
*

0 commit comments

Comments
 (0)