-
Notifications
You must be signed in to change notification settings - Fork 139
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
callbacks on natsConnection are called after natsConnection_destroy #735
Comments
an example output for the execution of this program is: MessagingController: 0x16ef0e4c0 |
@thierryba the connection event callbacks are indeed asynchronous, and may be called after
Note that if the intention is for Please let me know if it helps. I am hesitant to consider controls to "silence them" until I further understand your use case. |
Hello @levb , I suppose option a or b could be implemented. My question is more about: how can this be ok that there is no builtin way to control such things. I think it is a very common use case to embed such c-style functionality inside a c++ class. But there is hardly a way to get that done easily. It is at the very least very error prone. Having to add classes because the not-documented closedCB call is happening after I call destroy. Then I need to see if it was not already closed before and that opens up a can of worms. I have an ugly workaround to this. But an elegant solution would be really needed. |
@thierryba, understood. I could easily add I'd like to point out that |
@levb thanks you for your reply and I will be waiting for your decision on that one. |
@thierryba I think that adding Adding a synchronous method to wait for all callbacks to have finished, in the NATS client itself, seems counter to its asynchronous design philosophy. |
Ok, after running into this myself while fixing #771, I think what really needs to happen is natsConnection_Drain should wait for all async errors to be processed, much like it waits for all pending message callbacks to finish. I'll try to fix this one soon. |
Yay, it would be great to have it
Il Sab 13 Lug 2024, 07:36 Lev ***@***.***> ha scritto:
… Ok, after running into this myself while fixing #771
<#771>, I think what really needs
to happen is natsConnection_Drain should wait for all async errors to be
processed, much like it waits for all pending message callbacks to finish.
I'll try to fix this one soon.
—
Reply to this email directly, view it on GitHub
<#735 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA4I7OPEUY4TTKXGHWD2NS3ZMC4E7AVCNFSM6AAAAABE67CSLOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRWG44DENRYGQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Observed behavior
callbacks, especially ClosedCB and DisconnectedCB are called after the call to natsConnection_Destroy
Expected behavior
Either those should not get called or there should be a way to silence those.
Server and client version
I used the nats.c 3.8.0 connecting to demo.nats.io (see the code).
Host environment
No response
Steps to reproduce
I wrote a little c++ example program. It has a class called MessagingController. I took advantage of the fact that we ca set a closure on the callbacks to pass a pointer to that object so that in the callbacks it can redirect the calls to it. That works really well except when I destruct my MessagingController instance.
In that case, some callbacks are called after the destructor of that object. I believe my program uses a very common pattern for encapsulating the nats connection functionality.
But there is no easy way to prevent callbacks on my MEssagingController instance after the destructor.
In my real code, I ended up putting all the "valid" MessagingController instance in a static set so that I can check for validity there.
I would be very grateful for any insight on this one.
Here is the code (c++17):
The text was updated successfully, but these errors were encountered: