You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "Christopher L. Shannon (JIRA)" <ji...@apache.org> on 2015/06/18 23:08:00 UTC

[jira] [Commented] (AMQ-5340) QueueBrowser hangs until accidentally woken by expired messages background job

    [ https://issues.apache.org/jira/browse/AMQ-5340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14592505#comment-14592505 ] 

Christopher L. Shannon commented on AMQ-5340:
---------------------------------------------

This is not a problem and is working as intended.  Your issue is that you are using a transaction and you never call commit so your messages are never acknowledged by the broker.  Since your messages are never acknowledged, hasMoreElements() will always return true because the QueueBrowser is never notified that it is done browsing until the expire messages task runs and removes the messages.

In your test on line 115 when you create your session, if you change {{connection.createSession(true, Session.AUTO_ACKNOWLEDGE)}} to {{connection.createSession(false, Session.AUTO_ACKNOWLEDGE}} then your test will immediately finish and not hang.

 If you still want to use a transaction then you need to call commit on the session after you get each element or hasMoreElements() is never going to finish.  So you would change your loop to:

{code:java}
while (enumeration.hasMoreElements()) {
	TextMessage m = (TextMessage) enumeration.nextElement();
	browsed++;
        session.commit();
	LOG.info("B[{}]: {}", browsed, m.getText().substring(0, 100));
}
{code}

> QueueBrowser hangs until accidentally woken by expired messages background job
> ------------------------------------------------------------------------------
>
>                 Key: AMQ-5340
>                 URL: https://issues.apache.org/jira/browse/AMQ-5340
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: Broker
>    Affects Versions: 5.9.0, 5.10.0
>            Reporter: Vermeulen
>            Priority: Critical
>              Labels: QueueBrowser
>         Attachments: AMQ5340BrowsingPerformanceBug.java
>
>
> I would expect browsing a queue with only a few messages to not take a long time. Indeed it normally takes only a few ms. in my application. But sometimes the ActiveMQQueueBrowser hangs for up to 30 seconds at method before returning!
> When the issue occurs, the loop in hasMoreElements() calls waitForMessage() multiple times which times out after 2s at semaphore.wait(2000) without receiving any message from the broker. I found that when the broker's background job that checks for expired messages runs, the browser happens to be woken even if there are no expired messages. So setting the expireMessagesPeriod to a low value (e.g. 200ms) is a good workaround for this issue, but this is quite brittle because it uses internal broker implementation that may not even be related to the issue!
> To reproduce:
> - (this is what I do in my application) create a queue, send a few message with an expiration time of 10 seconds and repeatedly browse it until it is empty. If I browse the queue after these 10 seconds have passed, the issue occurs!
> - I can always reproduce the issue by running AMQ580BrowsingBug from the related bug report AMQ-4595: this browsing test seems to always hang. I slightly adjusted the test so you can easily change the expired messages period and see the runtime differ when changing this.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)