Hi All,
I've been doing some work this week with the new http_async_client module, it seems that with it's default behaviour it's not possible to execute another async query in the block immediately following the response, for example the following config:
``` request_route { if (!t_newtran()) { sl_reply_error(); exit(); } http_async_query("http://localhost:8090/req_1", '{"user":"$fU"}', "REQ_1"); }
route[REQ_1] { xlog("L_INFO", "route[REQ_1]: INIT\n"); if ($http_ok) { xlog("L_INFO", "route[REQ_1]: status $http_rs\n"); xlog("L_INFO", "route[REQ_1]: Sending REQ_2\n"); http_async_query("http://localhost:8090/req_2", '{"user":"$fU"}', "REQ_2"); } else { xlog("L_INFO", "route[REQ_1]: error $http_err)\n"); } }
route[REQ_2] { xlog("L_INFO", "route[REQ_2]: INIT\n"); if ($http_ok) { xlog("L_INFO", "route[REQ_2]: status $http_rs\n"); } else { xlog("L_INFO", "route[REQ_2]: error $http_err)\n"); } } ```
Generates the following error:
``` 10(11832) INFO: <script>: route[REQ_1]: INIT 10(11832) INFO: <script>: route[REQ_1]: status 200 10(11832) INFO: <script>: route[REQ_1]: Sending REQ_2 10(11832) WARNING: tm [t_suspend.c:186]: t_continue(): transaction is not suspended [53195:560306836] ```
Looking at the source, http_async_client calls t_suspend, then goes away and performs the request in the background. On response it calls t_continue and then this block in t_continue will continue execution, the second query will cause http_async_client to call t_suspend whilst sill executing from the previous t_continue. Once they query is sent, the first t_continue will complete, removing the T_ASYNC_SUSPENDED flag. When the second query returns it doesn't find the flag and so fails as shown.
I'm far from an expect on this so would really appreciate some pointers, it seems to fundamental to be a race condition in tm but the usage in http_async_client seems to match usage in other modules so I'm not sure on the best tactic. I've tried peppering append_branch and async_route call's in various places to no avail.
Full debug log here: http://pastebin.com/raw/rFmm0fmf
Any help appreciated,
--- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/645
Hi, sorry for the late answer, I have been travelling last week. You're right, the problem you are facing does not strictly depend on http_async_client module. Kamailio's async framework doesn't look to me to allow suspending again a transaction after having been resumed, even if it does not prevent the user from trying it. I don't think the changes to allow this are trivial, nor if there is any plan to implement this feature. Daniel, any thought?
Federico
--- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/645#issuecomment-222415723
Looking at the code I see the T_ASYNC_SUSPENDED flag is cleared at the end of t_continue(). Possible solutions:
* clear the flag earlier * use a static var to know that t_suspend() was executed inside the route block triggered by t_contine() * use a counter to track the level of suspend/continue stack
I didn't have the time to dig more and see which one would work the best and balance if there are side effects. First option would be simpler, I guess, if that works, it should be the way to go.
--- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/645#issuecomment-222446341
As usual, thanks for the feedback Daniel! I can work on it and report back.
--- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/645#issuecomment-222447182
The issue #644 is related to this one.
--- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/645#issuecomment-222453210
Pushed a patch (referred above) that relocates the resetting of T_ASYNC_SUSPENDED. Can you test and see the results? If all ok, it can be considered for backporting.
--- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/645#issuecomment-222457658
I think 827ec4f may have just cracked it, log output with that patch:
``` 10(19456) INFO: <script>: route[REQ_1]: INIT 10(19456) INFO: <script>: route[REQ_1]: status 200 10(19456) INFO: <script>: route[REQ_1]: Sending REQ_2 10(19456) INFO: <script>: route[REQ_2]: INIT 10(19456) INFO: <script>: route[REQ_2]: status 200 ```
Which is exactly as expected. Hopefully this doesn't have any further implications as it certainly seems the cleanest fix of those suggested.
Thanks again for the quick response
--- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/645#issuecomment-222460980
Closed #645.
--- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/645#event-675894765
OK, thanks for testing! I am going to close it here, if you find any new issue, report it in a new one.
--- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/645#issuecomment-222462638