Running 5.5.0-dev3
modparam("htable", "htable", "ipban=>size=8;autoexpire=300;dmqreplicate=1;") modparam("htable", "enable_dmq", 1) modparam("htable", "dmq_init_sync", 1) modparam("htable", "timer_procs", 4) modparam("htable", "timer_interval", 5) modparam("htable", "db_expires", 1) modparam("htable", "htable", "account=>size=4;dmqreplicate=1;") modparam("htable", "htable", "server=>size=4;autoexpire=15;")
I'm attempting to retrieve an auth token in the init process and also refresh the token upon expiration in the htable:expired event.
I'm seeing some behavior where every other execution of htable:expired the variable $sht(server=>auth::token) is set per kamcmd htable.dump server, however xinfo() reports that the token was retrieved in the variable $sht (server=>auth::token).
Please see remaining event route config below:
event_route[htable:mod-init] {
# generate auth token into
http_client_query("https://www.cryy.com/api/auth/token", '{"email": " brandon@cryy.com", "password":"XXXX"}', "$var(result)");
sht_lock("server=>auth::token");
$sht(server=>auth::token) = $var(result);
sht_unlock("server=>auth::token");
xinfo("AUTH_TOKEN_RECEIVED, $sht(server=>auth::token)");
}
event_route[htable:expired:server] {
# process expired htable, renew auth token
xinfo("AUTH_TOKEN_EXPIRED, lets retrieve a new one");
http_client_query("https://www.cryy.com/api/auth/token", '{"email": " brandon@cryy.com", "password":"XXXX"}', "$var(result)");
sht_lock("server=>auth::token");
$sht(server=>auth::time) = $TS;
$sht(server=>auth::token) = $var(result);
sht_unlock("server=>auth::token");
xinfo("AUTH_TOKEN_RECEIVED, $sht(server=>auth::token)");
xinfo("AUTH_TOKEN_TIME, $sht(server=>auth::time)");
}
I've tried both with locking and unlocking. Also one last thing worth mentioning is that on the alternation where kamcmd htable.dump server shows no auth token, $sht(server=>auth::time) is available, when the auth token is visible in kamcmd htable.dump server there is no sht(server=>auth::time) returned.
Also just to be explicitly clear -- xinfo() always returns AUTH_TOKEN_RECEIVED correctly in both event routes.
Perhaps I'm over looking something -- thank you for the help in advance.
- Brandon
As a workaround, this seems to work and $sht(server=>auth::token) is always reported back by kamcmd htable.dump server :
route[HTTP_AUTH_REPLY] {
xinfo("[$ci][$rm] HTTP_AUTH_REPLY received");
if($http_ok) {
xinfo("[HTTP_AUTH_REPLY][$http_rs] request was sucessful");
} else {
xinfo("[HTTP_AUTH_REPLY][$http_rs] request was unsucessful");
}
if($http_err) {
xinfo("[HTTP_AUTH_REPLY][ERROR] $http_err");
}
xinfo("[HTTP_AUTH_REPLY][RESPONSE][BODY] $http_rb");
# lock auth token
sht_lock("server=>auth::token");
# set token
$sht(server=>auth::token) = $http_rb;
# unlock auth token
sht_unlock("server=>auth::token");
}
event_route[htable:expired:server] {
xinfo("[HTABLE:expired:server] initializing");
$http_req(all) = $null;
$http_req(timeout) = 100;
$http_req(method) = "POST";
$http_req(suspend) = 1;
$http_req(hdr) = "Content-Type: application/json";
$http_req(body) = '{"email": "brandon@cryy.com", "password":"XXXX"}';
http_async_query("https://www.cryy.com/api/auth/token", "HTTP_AUTH _REPLY");
}
event_route[htable:mod-init] {
# generate auth token into
http_client_query("https://www.cryy.com/api/auth/token", '{"email": " brandon@cryy.com", "password":"XXXX"}', "$var(result)");
# lock auth token
sht_lock("server=>auth::token");
# set auth token
$sht(server=>auth::token) = $var(result);
# unlock auth token
sht_unlock("server=>auth::token");
xinfo("AUTH_TOKEN_RECEIVED, $sht(server=>auth::token)");
}
Is working -- I have to use http_client on htable module initialization, as http_async_client seems to start its workers after mod-init and results in:
Oct 31 21:04:37 main kamailio[2088]: ERROR: http_async_client [async_http.c:622]: async_push_query(): failed to pass the query to async workers
Oct 31 21:04:37 main kamailio[2088]: ERROR: http_async_client [async_http.c:588]: async_send_query(): failed to relay query: https://www.cryy.com/api/auth /token
(workers start after mod-init request) shown here:
Oct 31 21:04:38 main kamailio[2088]: INFO: http_async_client [async_http.c:84]: async_http_init_worker(): started worker process: 1
Oct 31 21:04:38 main kamailio[2088]: INFO: http_async_client [async_http.c:84]: async_http_init_worker(): started worker process: 2
Oct 31 21:04:38 main kamailio[2088]: INFO: http_async_client [async_http.c:84]: async_http_init_worker(): started worker process: 3
Oct 31 21:04:38 main kamailio[2088]: INFO: http_async_client [async_http.c:84]: async_http_init_worker(): started worker process: 4
So I suspect there are two separate issues going on here, 1) handling htable in memory between htable-mod-init and htable:expired:server and 2) unable to use http_async_client inside htable-mod:init. I've also double checked that these modules are loaded after htable in kamailio config.
I look forward to hearing any input anyone may have on this, thanks for your time in advance!
- Brandon
On Fri, Oct 30, 2020 at 10:55 PM Brandon Armstead brandon@cryy.com wrote:
Running 5.5.0-dev3
modparam("htable", "htable", "ipban=>size=8;autoexpire=300;dmqreplicate =1;") modparam("htable", "enable_dmq", 1) modparam("htable", "dmq_init_sync", 1) modparam("htable", "timer_procs", 4) modparam("htable", "timer_interval", 5) modparam("htable", "db_expires", 1) modparam("htable", "htable", "account=>size=4;dmqreplicate=1;") modparam("htable", "htable", "server=>size=4;autoexpire=15;")
I'm attempting to retrieve an auth token in the init process and also refresh the token upon expiration in the htable:expired event.
I'm seeing some behavior where every other execution of htable:expired the variable $sht(server=>auth::token) is set per kamcmd htable.dump server, however xinfo() reports that the token was retrieved in the variable $sht(server=>auth::token).
Please see remaining event route config below:
event_route[htable:mod-init] {
# generate auth token into http_client_query("https://www.cryy.com/api/auth/token", '{"email": "
brandon@cryy.com", "password":"XXXX"}', "$var(result)");
sht_lock("server=>auth::token"); $sht(server=>auth::token) = $var(result); sht_unlock("server=>auth::token"); xinfo("AUTH_TOKEN_RECEIVED, $sht(server=>auth::token)");
}
event_route[htable:expired:server] {
# process expired htable, renew auth token xinfo("AUTH_TOKEN_EXPIRED, lets retrieve a new one"); http_client_query("https://www.cryy.com/api/auth/token", '{"email": "
brandon@cryy.com", "password":"XXXX"}', "$var(result)");
sht_lock("server=>auth::token"); $sht(server=>auth::time) = $TS; $sht(server=>auth::token) = $var(result); sht_unlock("server=>auth::token"); xinfo("AUTH_TOKEN_RECEIVED, $sht(server=>auth::token)"); xinfo("AUTH_TOKEN_TIME, $sht(server=>auth::time)");
}
I've tried both with locking and unlocking. Also one last thing worth mentioning is that on the alternation where kamcmd htable.dump server shows no auth token, $sht(server=>auth::time) is available, when the auth token is visible in kamcmd htable.dump server there is no sht(server=>auth::time) returned.
Also just to be explicitly clear -- xinfo() always returns AUTH_TOKEN_RECEIVED correctly in both event routes.
Perhaps I'm over looking something -- thank you for the help in advance.
- Brandon
Hello,
On 31.10.20 06:55, Brandon Armstead wrote:
Running 5.5.0-dev3
modparam("htable", "htable", "ipban=>size=8;autoexpire=300;dmqreplicate=1;") modparam("htable", "enable_dmq", 1) modparam("htable", "dmq_init_sync", 1) modparam("htable", "timer_procs", 4) modparam("htable", "timer_interval", 5) modparam("htable", "db_expires", 1) modparam("htable", "htable", "account=>size=4;dmqreplicate=1;") modparam("htable", "htable", "server=>size=4;autoexpire=15;")
I'm attempting to retrieve an auth token in the init process and also refresh the token upon expiration in the htable:expired event.
I'm seeing some behavior where every other execution of htable:expired the variable $sht(server=>auth::token) is set per kamcmd htable.dump server, however xinfo() reports that the token was retrieved in the variable $sht(server=>auth::token).
I don't really get what you meant above, can you explicitly tell what is printed in the logs and kamcmd output in each case and what you expected to be there?
Cheers, Daniel
Please see remaining event route config below:
event_route[htable:mod-init]{
# generate auth token into
http_client_query("https://www.cryy.com/api/auth/token", '{"email": "brandon@cryy.com", "password":"XXXX"}', "$var(result)");
sht_lock("server=>auth::token");
$sht(server=>auth::token) = $var(result);
sht_unlock("server=>auth::token");
xinfo("AUTH_TOKEN_RECEIVED, $sht(server=>auth::token)");
}
event_route[htable:expired:server]{
# process expired htable, renew auth token
xinfo("AUTH_TOKEN_EXPIRED, lets retrieve a new one");
http_client_query("https://www.cryy.com/api/auth/token", '{"email": "brandon@cryy.com", "password":"XXXX"}', "$var(result)");
sht_lock("server=>auth::token");
$sht(server=>auth::time) = $TS;
$sht(server=>auth::token) = $var(result);
sht_unlock("server=>auth::token");
xinfo("AUTH_TOKEN_RECEIVED, $sht(server=>auth::token)");
xinfo("AUTH_TOKEN_TIME, $sht(server=>auth::time)");
}
I've tried both with locking and unlocking. Also one last thing worth mentioning is that on the alternation where kamcmd htable.dump server shows no auth token, $sht(server=>auth::time) is available, when the auth token is visible in kamcmd htable.dump server there is no sht(server=>auth::time) returned.
Also just to be explicitly clear -- xinfo() always returns AUTH_TOKEN_RECEIVED correctly in both event routes.
Perhaps I'm over looking something -- thank you for the help in advance.
- Brandon
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Daniel,
In short kamcmd does not reflect the value set in $sht(server=>auth ::token)
It alternates between being set and not being set (reflecting in kamcmd htable.dump
root@main:/etc/kamailio# kamcmd htable.dump server
{
entry: 11
size: 1
slot: {
{
name: auth::token
value: {"data":{"token":{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJDUllZIiwiaWF0IjoxNjA0MzQ2NzgzLCJleHAiOjE2MDQzNTAzODMsIm1ldGhvZCI6InBvc3Q6YXV0aDp0b2tlbiIsImFjY291bnQiOnsiaWQiOiIxIiwiZmlyc3RuYW1lIjoiVGVzdCIsImxhc3RuYW1lIjoiQXJtc3RlYWQiLCJlbWFpbCI6ImJyYW5kb25AY3J5eS5jb20ifSwic291cmNlIjp7ImFkZHJlc3MiOiIzNC45NC4xMjMuMTIxIn19.aFGWqQg31oNnw10XfZ61Xm5Jncvt7RoNri2ZuDJ6yLQ","header":{"alg":"HS256","typ":"JWT"},"payload":{"iss":"CRYY","iat":1604346783,"exp":1604350383,"method":"post:auth:token","account":{"id":"1","firstname":"Test","lastname":"Armstead","email":" brandon@cryy.com "},"source":{"address":"34.94.123.121"}},"signature":"aFGWqQg31oNnw10XfZ61Xm5Jncvt7RoNri2ZuDJ6yLQ"}}}
type: str
}
}
}
In the kamailio logs it always shows AUTH_TOKEN_RECEIVED (correctly, with the correct auth token), kamcmd dump of htable alternates between execution of this route: htable:expired:server
Exec 1:
auth::time => [timestamp]
Exec 2:
auth::token => token
Exec 3:
auth::time => [timestamp]
So on and so forth, [ kamcmd htable.dump server ] it does not correctly hold both $sht(server=>auth::time) and $sht(server=>auth::token) like it should, despite kamailio logs showing the HTTP_AUTH_TOKEN received message with the correct auth token (100% of the time).
It's almost like there is a race condition when using the modules http_client_query in both init and expired event route.
When I changed it to the resolved code block above separating the calls and introducing http_async_client inside htable:expired:server
The result is 100% of the time auth token exists correctly, just like the logs 100% of the time show the auth token received regardless of event_route implementation.
So somewhere somehow the problematic config causes the hash table to not store HTTP_AUTH_TOKEN it receives and logs.