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

[FIXED] EventLoop: Socket now closed only after event loop done polling #815

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kozlovic
Copy link
Member

The socket was closed by the NATS library itself, which could cause some issue when the event loop thread would still be polling it. We now defer to the event loop adapter to make sure that the event loop library is done polling before invoking a new function that will take care of closing the socket.

I have updated the event loop test (that simulates what our adapters are doing). The mockup event loop implementation is a bit too simplistic but should be ok for now. If we have issues, we would have to make the events a linked list.

Resolves #814

Signed-off-by: Ivan Kozlovic [email protected]

The socket was closed by the NATS library itself, which could cause
some issue when the event loop thread would still be polling it.
We now defer to the event loop adapter to make sure that the event
loop library is done polling before invoking a new function that
will take care of closing the socket.

I have updated the event loop test (that simulates what our adapters are
doing). The mockup event loop implementation is a bit too simplistic
but should be ok for now. If we have issues, we would have to make
the events a linked list.

Resolves #814

Signed-off-by: Ivan Kozlovic <[email protected]>
@kozlovic kozlovic requested a review from levb October 23, 2024 22:43
@kozlovic
Copy link
Member Author

@levb I would like if possible have @dmitry-sles-novikov build from this branch and test with it to see if that resolves the issue.

@levb Assuming we get an ok, note that although this is a fix, we have to add a new API in nats.h and also the event loop adapters now will use this new API. So not sure if it will have to be a 3.10 and not a fix to 3.9.

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 70.56%. Comparing base (1553d4a) to head (86df606).
Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
src/conn.c 84.61% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #815      +/-   ##
==========================================
+ Coverage   68.71%   70.56%   +1.85%     
==========================================
  Files          39       47       +8     
  Lines       15207    15455     +248     
  Branches     3143     3183      +40     
==========================================
+ Hits        10449    10906     +457     
+ Misses       1700     1472     -228     
- Partials     3058     3077      +19     

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

@@ -2146,9 +2146,21 @@ _evStopPolling(natsConnection *nc)

nc->sockCtx.useEventLoop = false;
nc->el.writeAdded = false;
s = nc->opts->evCbs.read(nc->el.data, NATS_EVENT_ACTION_REMOVE);
// The "write" event is added and removed as we write, however, we always
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 Right, matching the changes in natsLibevent_Read, thx for the explanation comment!

Copy link
Collaborator

@levb levb left a comment

Choose a reason for hiding this comment

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

LGTM, thx for the descriptive comments!

@levb
Copy link
Collaborator

levb commented Oct 24, 2024

@dmitry-sles-novikov standing by for your confirmation

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.

File descriptor is closed before async callbacks are called from libuv adapter
2 participants