Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loggerd: eliminate recursion from handle_encoder_msg #33453

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

deanlee
Copy link
Contributor

@deanlee deanlee commented Sep 4, 2024

Changes:

  1. Refactored handle_encoder_msg: Moved the encoding packet writing logic to a new function, write_encode_data,
  2. Eliminated Recursive Calls: Replaced recursive calls within handle_encoder_msg with direct calls to write_encode_data for writing queued packets in the new segment. This change prevents potential crashes by handling queued packets safely, even if they are out of sync with the encoderd.

3. Improved Memory Management: Replaced raw pointers with std::unique_ptr for managing Message objects, improving memory safety.
4. Removed Redundant Parameter: Removed the service.name parameter from handle_encoder_msg, as it duplicates the re.publish_name value already available through the re parameter.

Resolves #28857

Copy link
Contributor

This PR has had no activity for 9 days. It will be automatically closed in 2 days if there is no activity.

@github-actions github-actions bot added the stale label Sep 14, 2024
Copy link
Contributor

This PR has been automatically closed due to inactivity. Feel free to re-open once activity resumes.

Copy link
Contributor

This PR has had no activity for 9 days. It will be automatically closed in 2 days if there is no activity.

@github-actions github-actions bot added the stale label Sep 30, 2024
Copy link
Contributor

github-actions bot commented Oct 3, 2024

This PR has been automatically closed due to inactivity. Feel free to re-open once activity resumes.

@github-actions github-actions bot closed this Oct 3, 2024
@adeebshihadeh adeebshihadeh reopened this Oct 3, 2024
@github-actions github-actions bot removed the stale label Oct 4, 2024
Copy link
Contributor

This PR has had no activity for 9 days. It will be automatically closed in 2 days if there is no activity.

@adeebshihadeh
Copy link
Contributor

Can we break this up at all?

Copy link
Contributor

This PR has had no activity for 9 days. It will be automatically closed in 2 days if there is no activity.

@github-actions github-actions bot added the stale label Nov 12, 2024
@adeebshihadeh adeebshihadeh added this to the 0.9.8 milestone Nov 12, 2024
@adeebshihadeh adeebshihadeh self-assigned this Jan 22, 2025
@adeebshihadeh adeebshihadeh changed the title loggerd: extract write_encode_data and eliminate recursion from handle_encoder_msg loggerd: eliminate recursion from handle_encoder_msg Jan 23, 2025
@adeebshihadeh
Copy link
Contributor

@deanlee I'm ready to merge this PR, but it still doing too many things. can we break it up? ideally we just have one targeted PR at removing the recursion, then a followup that does the other things.

@deanlee deanlee marked this pull request as draft January 23, 2025 12:26
@deanlee
Copy link
Contributor Author

deanlee commented Jan 23, 2025

Done. I’ve simplified this PR by removing all other changes, leaving only the refactor that moves the encoded data writing logic from handle_encoder_msg to the new function write_encoder_data. The function body is nearly identical to the original code.

@deanlee deanlee marked this pull request as ready for review January 23, 2025 14:34
@maxime-desroches
Copy link
Contributor

@deanlee Do you have a way to reproduce memory leaks or weird behaviors when loggerd/encoderd get out of sync ?

@deanlee
Copy link
Contributor Author

deanlee commented Jan 24, 2025

If the encoderd restarts while loggerd is logging and there are encoded messages already queued in loggerd's queue, it will recursively call handle_encoder_msg. Due to the invalid segment_id of the queued items, the messages will be re-queued without being flushed to the new segment, resulting in infinite recursive calls when the system is out of sync.

The current recursive approach adds unnecessary complexity and introduces synchronization bugs without offering real benefits.

I'll look into adding a new test case later to capture this synchronization issue.

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.

memory leak when loggerd/encoderd get out of sync
3 participants