-
Notifications
You must be signed in to change notification settings - Fork 142
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
Timers still running after main() #72
Comments
MitigationA quick and dirty solution would be to make the variable i.e.: int main()
{
static struct my_context ctx; /* <= here */
init(&ctx);
fio_run_every(5000, 1, on_timer, &ctx, on_finish);
fio_start(.threads=1);
fini(&my_context);
} Another approach might make the Expected behavior?Right now, timers, unlike sockets, remain "alive" between calls to This is the current "expected behavior". I understand that it's questionable and I'm more then happy to get some feedback about this. The reason for this design, which you might not see as much in C as you might when using facil.io in Ruby (through the In Ruby, I might test some code in the terminal and start and stop facil.io multiple times. In fact, I sometimes do this in C when I'm testing something (though more rarely). i.e.: Lines 9549 to 9563 in ef041d9
Changing this behavior?I'm not sure if I can change this behavior without a major version change, since it breaks backwards compatibility / expectations (unless we consider this unexpected behavior and then it's a bug). This might only change in the 0.8.x release. Should I change this? I don't know. I'll need to consider this. I'd love to read some opinions. |
Thank you for the explanations and the If I understand you correctly,
Exposing the In order to restore the state of the application using
Is my underlying assumption correct that only these 3 global states of In any case, regarding option b), I suppose that would also break the current expectation, because then Option c) also does not seem to be very convenient, but at least it would warn me that I have to be careful with raised signals. On a side note: the current behaviour of just stopping the reactor and continuing "as normal" was very intuitive for me! I suppose, I am looking for an option to change the state from INIT to UNINIT (without resorting to EDIT: added |
Do you have any policy regarding ABI stability? If not, another option could be to pass one of your fancy optional arguments, e.g., |
It's a bit late here, so I'll try to be focused. Sorry if I don't make sense (was out drinking with friends).
I believe you could, should you desire, move the Normally, I would suggest using a state callback, adding your
Yes, it is. In fact, In addition,
Connection subscriptions will be terminated, so their However, global subscriptions (connectionless subscriptions) will stay valid and they will receive new messages once the reactor is restarted.
Actually, the global state is initialized by the The Line 3553 in ef041d9
I think maybe this is actually a valid expectation. The more I think about it the more I see the logic behind a more complete cleanup. Some things will NOT be uninitialized. The memory allocator and some other state data should remain in effect in order to allow for new timers / connections to be setup before running the reactor again... but its a fair approach. Maybe you could add a call to
Yes, I follow semantic versioning and avoid ABI breaking changes where patch versions are concerned. Minor versions might break ABI, but I would still try to avoid it. Then again, the library is a source code library, so ABI stability is, obviously, not something developers should expect.
👏🏻👏🏻🎉 |
I've added a patch for this in the 0.7.x branch. See how that works for you. |
Thank you for the quick fix, I will report back! Just one quick remark: I didn't look for Unfortunately, I'm quite busy now and need time to think about it. I will come back to your detailed reply above soon. |
Hi,
I'm having trouble with object lifetimes. My (dumbed down) application looks something like this:
I should add, that I link it dynamically to
libfacil.so
.When the application is interrupted by e.g. SIGINT, my understanding is that
facil.io
's custom signal handler will causefio_start()
to return tomain
. Aftermain
theatexit(3)
handlers run, including those that call_dl_fini
which calls:facil.io/lib/facil/fio.c
Line 3531 in ef041d9
Now, there is still the
on_timer
active and will be shutdown by callingon_finish
here:facil.io/lib/facil/fio.c
Line 3540 in ef041d9
main
already calledfini()
onctx
, leading to an access violation inon_finish
.Is this the intended behaviour and, if so, how am I using
facil.io
in the wrong way? My expectation was thaton_finish
(and actually the entire shutdown procedures fromfio_lib_destroy
) would be called beforefio_start()
returns and not when unloadinglibfacil.so
.I realize this is relatively easy to fix either by dynamic allocation of
ctx
and something like reference-counting, or by manuallydlopen
/dlclose
, but I am wondering whether there was a way to avoid both of these. Maybe by exposing some kind offio_init()
andfio_fini()
, which I could call aroundfio_start()
?Please forgive me if this issue is already covered by the documentation, I couldn't find any hint regarding timers or interaction of the
.on_unsubscribe
callbacks withfio_start()
or the shutdown procedure offacil.io
.The text was updated successfully, but these errors were encountered: