Skip to content

SyslogAppender packet splitting for large chunk counts#682

Open
jmestwa-coder wants to merge 1 commit into
apache:masterfrom
jmestwa-coder:syslogappender-bounded-packet-splitting
Open

SyslogAppender packet splitting for large chunk counts#682
jmestwa-coder wants to merge 1 commit into
apache:masterfrom
jmestwa-coder:syslogappender-bounded-packet-splitting

Conversation

@jmestwa-coder
Copy link
Copy Markdown
Contributor

Summary

Fix SyslogAppender packet splitting when large chunk counts cause the (x/y) suffix to exceed the reserved suffix space.

What changed

  • Replaced iterator-based splitting with bounded size_t index arithmetic.
  • Added suffix-aware chunk sizing to keep emitted payloads within MaxMessageLength.
  • Added explicit handling for cases where the full (x/y) suffix cannot fit alongside payload data.
  • Replaced fixed apr_snprintf suffix formatting with StringHelper::toString.
  • Added defensive guards around packet reservation for extremely large message counts.

Behavior

  • Normal packet splitting behavior is preserved for standard message sizes.
  • When the suffix cannot fit within MaxMessageLength, the appender now omits the suffix instead of emitting oversized packets.
  • A warning is logged when suffix omission occurs.

Tests

Added regression coverage for:

  • one-byte remainder splitting boundaries
  • large chunk-count suffix growth
  • payload length invariant enforcement
  • impossible suffix-fit scenarios

Result

Ensures emitted SyslogAppender payloads remain bounded by MaxMessageLength across large message and packet-count edge cases.

Comment thread src/main/cpp/syslogwriter.cpp Outdated

void SyslogWriter::write(const LogString& source)
{
#if defined(UNIT_TEST)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would this block ever get activated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UNIT_TEST is defined in syslogappendertestcase.cpp, so this path is only enabled for those tests.

The goal was to make the packet-size assertions deterministic without depending on UDP/network behavior. If there’s a preferred way to structure this kind of test in log4cxx, I’m happy to adjust it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would never get compiled with UNIT_TEST defined though, you would have to compile the library with that macro defined.

Instead, it would make more sense to make a helper/utility function that can take a string of arbitrary length and split it up into smaller strings of a given max length. This function would then get called by the SyslogAppender to split the log message up. This function can then be properly tested on its own.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion .

I reworked the patch to move the splitting logic into a dedicated helper that SyslogAppender calls directly, removed the UNIT_TEST interception path, and updated the tests to validate the helper behavior directly instead of capturing network writes.

If there’s still a simpler structure you’d prefer here, I’m happy to adjust it further.

@jmestwa-coder jmestwa-coder force-pushed the syslogappender-bounded-packet-splitting branch from 343e205 to 2af1fe0 Compare May 25, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants