Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClasspathXmlApplicationContext cannot be closed twice [SPR-13425] #18004

Closed
spring-projects-issues opened this issue Sep 3, 2015 · 1 comment
Closed
Assignees
Labels
in: core status: backported type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 3, 2015

Eric Vigeant opened SPR-13425 and commented

Here is some simple code that will show the pattern:

ClassPathXmlApplicationContext ctx = ...

ctx.refresh(); // This works as expected
ctx.close(); // This closes the context correctly
ctx.refresh(); // This restarts the context properly
ctx.close(); // This does NOT close the context

I traced it down to the "closed" field in AbstractApplicationContext, it is initialized to false, it is set to true when closing, but it is never set again to false after it is restarted. This causes the doClose() method to do nothing.


Affects: 4.1.7, 4.2 GA

Issue Links:

  • #18132 Close processing triggered by shutdown hook isn't thread safe

Referenced from: commits 811de8e, 57125c0

Backported to: 4.1.8

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 3, 2015

Juergen Hoeller commented

close() isn't actually defined for repeated calls on the same ApplicationContext instance, in contrast to refresh() which - on a re-refreshable context - does allow for repeated calls. In a sequence as yours, you'd just call refresh() twice, with a single close() call at the end.

That said, it should be easy enough to allow for repeated closing and refreshing here. There might be subtleties beyond the "closed" field, but even with that in mind, it's worth trying since regular single close() calls will keep working fine... I'm not expecting any regressions there.

Juergen

@spring-projects-issues spring-projects-issues added status: backported type: enhancement in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.2.2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: backported type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants