Skip to content

Conversation

kozlovic
Copy link
Member

@kozlovic kozlovic commented Jul 3, 2025

This was likely introduced in PR #815 when delaying the close of the socket based on the event loop adapter invoking a NATS C callback to indicate that it is safe to do so. The libuv adapter is doing the right thing, however the libevent was not since it was creating a one-time event based on EV_TIMEOUT passing the socket to close, however, in that mode the socket from the callback is always set to -1. We have to pass the socket to close though the nle object.

I also made the natsLibevent_Detach() function schedule an event to ensure that a _freeCb is now invoked after execution of the _closeCb.

Resolves #879

Signed-off-by: Ivan Kozlovic ivan@synadia.com

This was likely introduced in PR #815 when delaying the close of the
socket based on the event loop adapter invoking a NATS C callback
to indicate that it is safe to do so. The `libuv` adapter is doing
the right thing, however the `libevent` was not since it was creating
a one-time event based on `EV_TIMEOUT` passing the socket to close,
however, in that mode the socket from the callback is always set
to `-1`. We have to pass the socket to close though the `nle` object.

I also made the `natsLibevent_Detach()` function schedule an event
to ensure that a `_freeCb` is now invoked *after* execution of the
`_closeCb`.

Resolves #879

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
@kozlovic kozlovic requested a review from levb July 3, 2025 23:01
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.09%. Comparing base (1553d4a) to head (9605fd0).
Report is 68 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #882      +/-   ##
==========================================
+ Coverage   68.71%   70.09%   +1.38%     
==========================================
  Files          39       47       +8     
  Lines       15207    15555     +348     
  Branches     3143     3202      +59     
==========================================
+ Hits        10449    10903     +454     
+ Misses       1700     1577     -123     
- Partials     3058     3075      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kozlovic kozlovic requested review from derekcollison and removed request for levb July 12, 2025 01:18
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

LGTM

@kozlovic kozlovic merged commit de58a3f into main Jul 12, 2025
32 of 33 checks passed
@kozlovic kozlovic deleted the fix_879 branch July 12, 2025 18:23
github-actions bot pushed a commit that referenced this pull request Jul 12, 2025
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.

When using the Libevent library, natsConnection_Destroy() does not actually close the TCP connection
2 participants