Skip to content

DefaultMessageListenerContainer doesn't shutdown gracefully if long recovery interval is set [SPR-14200] #18774

@spring-projects-issues

Description

@spring-projects-issues

Oleg Ivanov opened SPR-14200 and commented

Currently in DefaultMessageListenerContainer.applyBackOffTime(BackOffExecution execution) function the current thread is sleeping during the back off interval. This prevents container to shutdown correctly (as it waits for this thread to wake up).

I suggest to rewrite this function using .wait() calls:

        final long interval = execution.nextBackOff();
        if (interval == BackOffExecution.STOP)
            return false;

        if (isRecovering() && interrupted)
            // Interrupted right before and still failing... give up.
            return false;

        try {
            synchronized (this.lifecycleMonitor) {
                final long start = System.currentTimeMillis();
                while (isActive() && System.currentTimeMillis() - start < interval) {
                    final long timeout = getReceiveTimeout();
                    this.lifecycleMonitor.wait(timeout > 0 ? timeout : DEFAULT_RECEIVE_TIMEOUT);
                }
            }
        } catch (InterruptedException interEx) {
            // Re-interrupt current thread, to allow other threads to react.
            Thread.currentThread().interrupt();
            if (isRecovering())
                this.interrupted = true;
        }

        return true;

Affects: 4.2.5

Issue Links:

Referenced from: commits 6ab8d36

Metadata

Metadata

Assignees

Labels

in: messagingIssues in messaging modules (jms, messaging)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions