Skip to content

Does not catch exception during stopping Lifecycle bean can cause resource leak [SPR-6770] #11436

@spring-projects-issues

Description

@spring-projects-issues

Liu, Yinwei David opened SPR-6770 and commented

When Spring stops its application context, it will call DefaultLifecycleProcessor to stop all Lifecycle beans in its context. However, it does not catch the exception when it stops beans. The problem of not catching exception is that it can cause the resource leak.
E.g. we have 5 Lifecycle beans which should be stopped, if the second bean throws one Exception which can cause Spring gives up stopping rest beans, so that other beans are unable to release the resource they have which leads to resource leak.

Can we catch the exception during bean.stop() and logging it?

 
if (bean.isRunning()) {
  if (bean instanceof SmartLifecycle) {
  	((SmartLifecycle) bean).stop(new Runnable() {
   public void run() {
   	latch.countDown();
   }
  	});
  }
  else {
  	bean.stop();
  }
}

Affects: 3.0 GA

Issue Links:

Referenced from: commits a897e3f

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions