Module: sip-router Branch: master Commit: 7f54aacb740011abe968eb599509cf296e003a61 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7f54aacb...
Author: Anca Vamanu anca.vamanu@1and1.ro Committer: Anca Vamanu anca.vamanu@1and1.ro Date: Thu Mar 8 17:26:06 2012 +0200
modules_k/presence: Fixed bug - calling child_init in process main
Process main calls child_init with process type PROC_MAIN before forking the TCP children. Since presence module opens database connection in child_init, this resulted in connection being inherited by the TCP children and wierd things happening when doing DB operations. Since there is no place in main() where child_init is called after all the forks, for the subs_db_mode=WRITE_BACK when process main needs to dump the subscribe table in database at shutdown, the solution was to open the database connection in mod_destroy().
---
modules_k/presence/presence.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/modules_k/presence/presence.c b/modules_k/presence/presence.c index 58ddbd4..dd415f7 100644 --- a/modules_k/presence/presence.c +++ b/modules_k/presence/presence.c @@ -369,7 +369,7 @@ static int mod_init(void) */ static int child_init(int rank) { - if (rank==PROC_INIT || rank==PROC_TCP_MAIN) + if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) return 0; /* do nothing for the main process */
pid = my_pid(); @@ -462,8 +462,14 @@ static int mi_child_init(void) */ static void destroy(void) { - if(subs_htable && pa_db) - timer_db_update(0, 0); + if(subs_htable && subs_dbmode == WRITE_BACK) { + /* open database connection */ + pa_db = pa_dbf.init(&db_url); + if (!pa_db) { + LM_ERR("mod_destroy: unsuccessful connecting to database\n"); + } else + timer_db_update(0, 0); + }
if(subs_htable) destroy_shtable(subs_htable, shtable_size);
Hello,
On 3/8/12 4:49 PM, Anca Vamanu wrote:
Module: sip-router Branch: master Commit: 7f54aacb740011abe968eb599509cf296e003a61 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7f54aacb...
Author: Anca Vamanuanca.vamanu@1and1.ro Committer: Anca Vamanuanca.vamanu@1and1.ro Date: Thu Mar 8 17:26:06 2012 +0200
modules_k/presence: Fixed bug - calling child_init in process main
Process main calls child_init with process type PROC_MAIN before forking the TCP children. Since presence module opens database connection in child_init, this resulted in connection being inherited by the TCP children and wierd things happening when doing DB operations.
Have you noticed db connection sharing between processes?
The DB API stores for each connection the PID of the process opening it. When a process is asking for a db connection and URL matches and existing one, current PID is checked with connection pid and if they differ, a new connection should be created, thus no connection sharing should be between processes. Is the db connection open in main process used in other processes?
Cheers, Daniel
Hi Daniel,
On 03/12/2012 05:02 PM, Daniel-Constantin Mierla wrote:
Hello,
On 3/8/12 4:49 PM, Anca Vamanu wrote:
Module: sip-router Branch: master Commit: 7f54aacb740011abe968eb599509cf296e003a61 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7f54aacb...
Author: Anca Vamanuanca.vamanu@1and1.ro Committer: Anca Vamanuanca.vamanu@1and1.ro Date: Thu Mar 8 17:26:06 2012 +0200
modules_k/presence: Fixed bug - calling child_init in process main
Process main calls child_init with process type PROC_MAIN before forking the TCP children. Since presence module opens database connection in child_init, this resulted in connection being inherited by the TCP children and wierd things happening when doing DB operations.
Have you noticed db connection sharing between processes?
The DB API stores for each connection the PID of the process opening it. When a process is asking for a db connection and URL matches and existing one, current PID is checked with connection pid and if they differ, a new connection should be created, thus no connection sharing should be between processes. Is the db connection open in main process used in other processes?
Yes, this was the case db connection opened by main process inherited by the TCP children. The bug was in presence module and it was introduced by me a couple of weeks ago when I permitted calling child_init function for rank PROC_MAIN.
I noticed only last week when I did the fix that the main process calls child_init with this PROC_MAIN rank before forking the tcp children. Actually there isn't any place now where child_init is called by proc main after all forks.
I understand that the new DB connection is made quite safe to avoid this case, but the bad thing was that presence module had in child_init somewhere at the start:
if (pa_db) return 0;
So it actually did not call the init connection function again for those children.
Regards, Anca
Cheers, Daniel
Hello,
ok, thanks for explanation -- I saw the commit message and I wondered if there was something left wrong with the way connections are created now to avoid sharing.
Cheers, Daniel
On 3/12/12 4:09 PM, Anca Vamanu wrote:
Hi Daniel,
On 03/12/2012 05:02 PM, Daniel-Constantin Mierla wrote:
Hello,
On 3/8/12 4:49 PM, Anca Vamanu wrote:
Module: sip-router Branch: master Commit: 7f54aacb740011abe968eb599509cf296e003a61 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7f54aacb...
Author: Anca Vamanuanca.vamanu@1and1.ro Committer: Anca Vamanuanca.vamanu@1and1.ro Date: Thu Mar 8 17:26:06 2012 +0200
modules_k/presence: Fixed bug - calling child_init in process main
Process main calls child_init with process type PROC_MAIN before forking the TCP children. Since presence module opens database connection in child_init, this resulted in connection being inherited by the TCP children and wierd things happening when doing DB operations.
Have you noticed db connection sharing between processes?
The DB API stores for each connection the PID of the process opening it. When a process is asking for a db connection and URL matches and existing one, current PID is checked with connection pid and if they differ, a new connection should be created, thus no connection sharing should be between processes. Is the db connection open in main process used in other processes?
Yes, this was the case db connection opened by main process inherited by the TCP children. The bug was in presence module and it was introduced by me a couple of weeks ago when I permitted calling child_init function for rank PROC_MAIN.
I noticed only last week when I did the fix that the main process calls child_init with this PROC_MAIN rank before forking the tcp children. Actually there isn't any place now where child_init is called by proc main after all forks.
I understand that the new DB connection is made quite safe to avoid this case, but the bad thing was that presence module had in child_init somewhere at the start:
if (pa_db) return 0;
So it actually did not call the init connection function again for those children.
Regards, Anca
Cheers, Daniel