Skip to content

Race condition in DefaultHeaderChannelRegistry during application shutdown causes error log #10547

@francisco-bru

Description

@francisco-bru

In what version(s) of Spring Integration are you seeing this issue?

6.5.2

Describe the bug

When stopping an application, the following error log is generated:

ERROR Unexpected error occurred in scheduled taskorg.springframework.core.task.TaskRejectedException: ExecutorService in shutdown state did not accept task: bean 'integrationHeaderChannelRegistry'
 at org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler.schedule(ThreadPoolTaskScheduler.java:430)
Caused by: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@7bc9f638[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@3ecb6f85[Wrapped task = DelegatingErrorHandlingRunnable for bean 'integrationHeaderChannelRegistry']] rejected from org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler$1@57715118[Shutting down, pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 1225]

Since this happens during application shutdown, it does not appear to have any side effects. However, because this message is logged at the error level, it can cause uncertainty about whether the application has shut down correctly, or if something has actually failed.

Upon reviewing the affected class, DefaultHeaderChannelRegistry, it seems possible that a race condition occurs between the call to stop() (executed by the lifecycle processor) and a scheduled invocation of the run() method of the reaper.

Perhaps, in the run() method, scheduling of the next execution could be skipped if explicitlyStopped==true, to prevent this situation from occurring, in which the task scheduler is already stopping and no longer accepting tasks.

To Reproduce (Sometimes not always)

  1. Start a Spring Integration application using DefaultHeaderChannelRegistry.
  2. Shut down the application, triggering the lifecycle processor to call stop().
  3. Observe the logs for the error at shutdown.

Expected behavior

No error-level log should be generated by the scheduled reaper when the application is being shut down intentionally.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions