Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AA5E2200BCC for ; Tue, 29 Nov 2016 19:00:49 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id A9995160B15; Tue, 29 Nov 2016 18:00:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F2F5B160AFC for ; Tue, 29 Nov 2016 19:00:48 +0100 (CET) Received: (qmail 60820 invoked by uid 500); 29 Nov 2016 18:00:48 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 60811 invoked by uid 99); 29 Nov 2016 18:00:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Nov 2016 18:00:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B88C3E02AB; Tue, 29 Nov 2016 18:00:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@activemq.apache.org Message-Id: <92453dc9e4d64487a8288344a88754d5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: activemq git commit: AMQ-5659: Add safety measure against infinite loop when store exception prevents message removal. Thanks to metatechbe for the patch. This fixes #72. Date: Tue, 29 Nov 2016 18:00:47 +0000 (UTC) archived-at: Tue, 29 Nov 2016 18:00:49 -0000 Repository: activemq Updated Branches: refs/heads/master b98811358 -> 78492febc AMQ-5659: Add safety measure against infinite loop when store exception prevents message removal. Thanks to metatechbe for the patch. This fixes #72. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/78492feb Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/78492feb Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/78492feb Branch: refs/heads/master Commit: 78492febc858ff06c1ef42e49cdfefc39a6855fb Parents: b988113 Author: Claus Ibsen Authored: Tue Nov 29 18:58:17 2016 +0100 Committer: Claus Ibsen Committed: Tue Nov 29 18:58:17 2016 +0100 ---------------------------------------------------------------------- .../org/apache/activemq/broker/region/Queue.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/78492feb/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java ---------------------------------------------------------------------- diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java index 6a42ebc..409c978 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java @@ -1239,6 +1239,8 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index public void purge() throws Exception { ConnectionContext c = createConnectionContext(); List list = null; + long previousDequeueCount = -1; + long previousDequeueCountRepeated = 1L; long originalMessageCount = this.destinationStatistics.getMessages().getCount(); do { doPageIn(true, false, getMaxPageSize()); // signal no expiry processing needed. @@ -1250,6 +1252,19 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index } for (MessageReference ref : list) { + long currentDequeueCount = this.destinationStatistics.getDequeues().getCount(); + if (previousDequeueCount == currentDequeueCount) { + previousDequeueCountRepeated++; + if (previousDequeueCountRepeated >= 3) { + // Break the infinite loop in case the removal fails + // 3 times in a row -> error is fatal and not transient. + LOG.error("Aborted purge operation after attempting to delete messages failed 3 times in a row (to avoid endless looping)"); + throw new RuntimeException("Purge operation failed to delete messages failed 3 times in a row (to avoid endless looping)"); + } + } else { + previousDequeueCount = currentDequeueCount; + previousDequeueCountRepeated = 0L; + } try { QueueMessageReference r = (QueueMessageReference) ref; removeMessage(c, r);