Summary:ASTERISK-16756: Wrapuptime sometimes not respected
Reporter:laszlovl (lvl)Labels:
Date Opened:2010-09-30 10:09:35Date Closed:2011-06-07 14:04:55
Versions:Frequency of
Description:Ever since at least asterisk we are experiencing that occasionally (perhaps every 1 out of 10 calls) our WRAPUPTIME is being ignored. I finally got around to setting up an environment where we can somewhat reproduce the issue. This environment runs

First of all, all the relevant parts of our configuration:

--- queues.conf ---
shared_lastcall = yes


--- extensions.conf ---
; we only use dynamic agents, through a local channel because we need to do AGI processing before and after an agent is called
; because of the local channel, we specify a custom state interface that we set INUSE/NOT_INUSE in the phones context
exten => s,n(login),AddQueueMember(queue1,Local/${extension}@phones/n,,,,Custom:inuse-${extension})

exten => _X,1,Gosub(callphone,s,1(${EXTEN}))

exten => s,1,Set(DEVICE_STATE(Custom:inuse-${ARG1})=INUSE)

exten => s,n,Dial(SIP/phone${ARG1})

exten => h,1,Set(DEVICE_STATE(Custom:inuse-${ARG1})=NOT_INUSE)

Most of the times this works fine. An agent hangs up a call, and gets (at least) a 60 second pause before another call is offered to him. But sometimes, RIGHT after an agent's call is hungup (to be exact, it happens right after the Custom:inuse devstate is set back to NOT_INUSE. at this time the call hasn't fully terminated yet by asterisk), the agent is offered another call. See for example:

[Sep 30 15:06:10] VERBOSE[9694] pbx.c:     -- Executing [h@callphone:1] ExecIf("Local/99@phones-78e9;2", "1?Set(DEVICE_STATE(Custom:inuse-99)=NOT_INUSE)") in new stack
[Sep 30 15:06:10] VERBOSE[9694] pbx.c:     -- Executing [h@callphone:2] AGI("Local/99@phones-78e9;2", "hangup.agi") in new stack

[Sep 30 15:06:10] VERBOSE[9701] pbx.c:     -- Executing [99@phones:1] Gosub("Local/99@phones-fa31;2", "callphone,s,1(99)") in new stack
[Sep 30 15:06:10] VERBOSE[9701] pbx.c:     -- Executing [s@callphone:1] ExecIf("Local/99@phones-fa31;2", "1?Set(DEVICE_STATE(Custom:inuse-99)=INUSE)") in new stack

[Sep 30 15:06:10] VERBOSE[9694] pbx.c:     -- Executing [h@callphone:3] NoOp("Local/99@phones-78e9;2", "") in new stack
[Sep 30 15:06:10] VERBOSE[9694] pbx.c:   == Spawn extension (callphone, s, 15) exited non-zero on 'Local/99@phones-78e9;2'

When this problem occurs, it always occurs after the previous call has been hungup: in the same second. Never later than that. Perhaps the wrapuptime is being ignored when the queue engine tries to offer a call at exactly the same moment that another call is being hung up. Any clues?
Comments:By: Leif Madsen (lmadsen) 2010-10-05 09:40:16

I'm thinking the fact that an AGI is being executed after you set the user to NOT_INUSE may have something to do with that. During the time the AGI() is being executed and torn down, the agent is set as NOT_INUSE. I'd suggest you move the AGI() to the line prior to setting the device states as NOT_INUSE and see if that helps any.

Alternatively, you could get rid of the custom device state altogether if you are using just SIP end points. In this case you could just use the "stateinterface" argument to AddQueueMember() and use SIP/phone99 instead of the custom device state. That is likely more accurate anyways.

By: laszlovl (lvl) 2010-10-05 11:06:30

I think you are right, I had coincidentally just come to the same conclusion.

Didn't consider that at first, because the AGI script almost instantly forks itself, but apparently the small delay it caused between the DEVSTATE set to NOT_INUSE and the call being hungup (and thus the agent's lastcall property being set) was enough to frequently cause a problem. I moved the SET(DEVICE_STATE) to the end of the h extension and the problem seems to have disappeared.

I believe that we have a good reason for using a custom devstate instead of the SIP address, but I'll check it over to be sure.

Thanks for your input!

By: laszlovl (lvl) 2010-10-05 11:37:41

(Yeah, we do. There is a bunch of logic - AGI scripts etc - in the callphone context before the Dial() is executed. If we use the SIP address as stateinterface; the agent won't be marked as busy until the Dial() is reached, and there's a chance the agent will be offered multiple simultaneous calls)

This bug can probably be closed.

By: Leif Madsen (lmadsen) 2010-10-12 10:04:19

Closing per the reporter. Thanks! (If you have further issues you think are a bug, please open a new issue versus reopening this one. Thanks!)