Skip to content

chore(liblogosdelivery): node_api destroy move + security/resource fixes#3736

Merged
Ivansete-status merged 1 commit intomasterfrom
chore-libdelivery-api-security
Mar 2, 2026
Merged

chore(liblogosdelivery): node_api destroy move + security/resource fixes#3736
Ivansete-status merged 1 commit intomasterfrom
chore-libdelivery-api-security

Conversation

@NagyZoltanPeter
Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter commented Feb 25, 2026

Summary

  • move destroy api to node_api
  • add security checks
  • fix possible resource leak

Scope after split

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses security concerns in the FFI API and adds health status monitoring capabilities to liblogosdelivery. The changes improve resource management, add partial race condition protection for event callbacks, and enable connection status monitoring through the FFI interface.

Changes:

  • Added Lock-based protection for event callback setter to mitigate race conditions
  • Implemented resource cleanup when FFI thread request submission fails during node creation
  • Added EventConnectionStatusChange listener to expose health status events to FFI consumers

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
liblogosdelivery/liblogosdelivery.nim Removed logosdelivery_destroy function (relocated to node_api.nim)
liblogosdelivery/declare_lib.nim Added Lock import and lock-protected event callback setter to prevent race conditions
liblogosdelivery/logos_delivery_api/node_api.nim Added logosdelivery_destroy function, health event listener, resource cleanup on creation failure, and event listener cleanup in stop

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +83 to +117
$newJsonEvent("connection_status_change", event),
).valueOr:
chronicles.error "ConnectionStatusChange.listen failed", err = $error
return err("ConnectionStatusChange.listen failed: " & $error)
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

If event listener registration fails (e.g., MessageSentEvent.listen succeeds but MessageErrorEvent.listen fails), the function returns early without cleaning up the previously registered listeners. This could lead to orphaned event listeners that continue to trigger callbacks even though the node never fully started. Consider adding cleanup logic in the error paths, or using a defer block with a success flag to ensure listeners are cleaned up on failure.

Copilot uses AI. Check for mistakes.
echo "error: invalid context in logosdelivery_set_event_callback"
return

# prevent race conditions that might happen due incorrect usage.
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

Spelling error in comment: "due incorrect usage" should be "due to incorrect usage".

Suggested change
# prevent race conditions that might happen due incorrect usage.
# prevent race conditions that might happen due to incorrect usage.

Copilot uses AI. Check for mistakes.
chronicles.error "MessagePropagatedEvent.listen failed", err = $error
return err("MessagePropagatedEvent.listen failed: " & $error)

let ConnectionStatusChangeListener = EventConnectionStatusChange.listen(
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The variable name ConnectionStatusChangeListener should follow camelCase convention to be consistent with the other listener variables (sentListener, errorListener, propagatedListener) in the same function. Consider renaming it to connectionStatusChangeListener.

Suggested change
let ConnectionStatusChangeListener = EventConnectionStatusChange.listen(
let connectionStatusChangeListener = EventConnectionStatusChange.listen(

Copilot uses AI. Check for mistakes.
Comment on lines +83 to +117
$newJsonEvent("connection_status_change", event),
).valueOr:
chronicles.error "ConnectionStatusChange.listen failed", err = $error
return err("ConnectionStatusChange.listen failed: " & $error)
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The listener variables (sentListener, errorListener, propagatedListener, ConnectionStatusChangeListener) are assigned but never used. While this may be intentional if the listeners are automatically managed by the event broker system, consider whether these variables should be stored or if they can be ignored with an underscore prefix (e.g., _ = MessageSentEvent.listen(...)). If they need to be stored for cleanup, they should be saved in the context. Note that cleanup currently uses dropAllListeners which doesn't require these handles.

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +134
MessageErrorEvent.dropAllListeners(ctx.myLib[].brokerCtx)
MessageSentEvent.dropAllListeners(ctx.myLib[].brokerCtx)
MessagePropagatedEvent.dropAllListeners(ctx.myLib[].brokerCtx)
EventConnectionStatusChange.dropAllListeners(ctx.myLib[].brokerCtx)
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

Event listener cleanup in logosdelivery_stop_node should ideally happen after the node is stopped, not before. If the node emits events during shutdown, those events won't be properly handled since the listeners have already been dropped. Consider moving the dropAllListeners calls after the ctx.myLib[].stop() call, or handle this within the stop implementation itself.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@fcecin fcecin left a comment

Choose a reason for hiding this comment

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

LGTM!

@NagyZoltanPeter NagyZoltanPeter force-pushed the chore-libdelivery-api-security branch from 4e74433 to 8e41a27 Compare February 26, 2026 13:48
@NagyZoltanPeter NagyZoltanPeter changed the title Chore: liblogosdelivery: api security + health api support chore(liblogosdelivery): node_api destroy move + security/resource fixes Feb 26, 2026
@Ivansete-status Ivansete-status merged commit db19da9 into master Mar 2, 2026
17 checks passed
@Ivansete-status Ivansete-status deleted the chore-libdelivery-api-security branch March 2, 2026 17:56
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.

4 participants