Summary:ASTERISK-04893: queue_log simultaneous write problem
Reporter:mike9 (mike9)Labels:
Date Opened:2005-08-24 13:10:31Date Closed:2008-01-15 15:48:01.000-0600
Versions:Frequency of
Environment:Attachments:( 0) 20050909__bug5020.diff.txt

1) There is call(s) waiting in a queue
2) Agent logs in via AgentCallbackLogin
3) Agent's phone rings immediately..


CONNECT event is generated in queue_log

AGENTCALLBACKLOGIN is not generated in queue_log


I am presuming both events are happening in the same time space and trying to write to queue_log at the same time.
Comments:By: mike9 (mike9) 2005-08-26 14:05:34

looks to have the same problem in 1.0-stable

By: Michael Jerris (mikej) 2005-09-02 20:57:45

Are you able to produce a patch to correct this problem?

By: mike9 (mike9) 2005-09-06 07:44:21

While I know this is not a correct fix, the following seems to fix it.. (not sure as of yet what else this breaks)

--- chan_agent.c.orig   2005-09-06 08:42:30.322897008 -0400
+++ chan_agent.c        2005-09-06 08:43:40.099289384 -0400
@@ -1844,8 +1844,10 @@
                                                               ast_log(LOG_WARNING, "Unable to set write format to %d\n", ast_best_codec(chan->nativeformats));
                                               /* Check once more just in case */
                                               if (p->chan)
                                                       res = -1;
                                               if (callbackmode && !res) {
                                                       /* Just say goodbye and be done with it */
                                                       if (!ast_strlen_zero(p->loginchan)) {

By: Tilghman Lesher (tilghman) 2005-09-06 18:48:30

Because queue_log is opened in append mode and the log statement is all written with one system call, there is no race condition between two things calling queue_log at once.  There is another problem here.

By: Tilghman Lesher (tilghman) 2005-09-06 19:07:53

The real problem is that as soon as we define an Agent, it's available to the Queue to answer a call.  We'll probably need some coordinated changes between app_queue and chan_agent such that app_queue will not pickup an agent who has just logged in until the login process is complete.

By: mike9 (mike9) 2005-09-07 07:36:15

Since 'res' gets set to '-1' @ chan_agent.c:1847, 'if (callbackmode && !res)' @ chan_agent.c:1849 is false, skipping the Agentcallbacklogin log write, as well as the Agentcallbacklogin manager event..

By: Tilghman Lesher (tilghman) 2005-09-07 08:57:21

Right, because the channel is getting seized by a queue.  We need to prevent it from being seized until the very end of this routine (when the channel is hung up).

By: mike9 (mike9) 2005-09-07 09:01:59

would setting a 'wrapuptime' in the agents agent_pvt struct help with a delay?

By: Tilghman Lesher (tilghman) 2005-09-08 15:55:38

You're welcome to try it; I doubt it'll change anything, though.

By: Tilghman Lesher (tilghman) 2005-09-08 16:34:07

See if this solves it.

By: mike9 (mike9) 2005-09-13 07:27:40

I applied this patch yesterday, so it could get some good usage, and it seems to do the trick... thanks!

By: Kevin P. Fleming (kpfleming) 2005-09-13 21:01:29

Committed to CVS HEAD, thanks!

By: Digium Subversion (svnbot) 2008-01-15 15:48:01.000-0600

Repository: asterisk
Revision: 6577

U   trunk/channels/chan_agent.c

r6577 | kpfleming | 2008-01-15 15:48:01 -0600 (Tue, 15 Jan 2008) | 2 lines

ensure that agent channels don't get seized during login (issue ASTERISK-4893)