vaadin / vaadin/framework

GlobalResourceHandler not cleaned up when UI gets detached

Open
#12,094 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Stale workaround
Dominant language
Java
Stars
1.8k
Forks
717
Avg merge
2d 6h
Merged PRs (30d)
3

Description

When an UI is closed, detached or times out. The GlobalResourceHandler is not cleaned up as cleanConnectorMap is never called again.

Demo
public class DemoUI extends UI {

	Label				label	= new Label("test");
	private final Field	usedResourcesField;

	public DemoUI() throws Exception {
	usedResourcesField = GlobalResourceHandler.class.getDeclaredField("usedResources");
		usedResourcesField.setAccessible(true);
	}

	@Override
	protected void init(final VaadinRequest request) {
		final Resource resource = new FileResource(new File("test"));
		getSession().getGlobalResourceHandler(true).register(resource, this);

		setPollInterval(1000);
		addPollListener(poll -> {

			final GlobalResourceHandler handler = getSession().getGlobalResourceHandler(false);
			Map<ClientConnector, ?> usedResources;
			final Collection<UI> activeUIs = getSession().getUIs();
			try {
				usedResources = (Map<ClientConnector, ?>) usedResourcesField.get(handler);

				label.setValue(
					Instant.now() + ". this is " + toString() + "; active resources: " + usedResources.keySet() + "; active uis: "
							+ activeUIs
				);
			} catch (final Exception e) {
				e.printStackTrace();
			}

		});
		setContent(label);
	}
}
Actual Behaviour

After opening two tabs and closing one. After some time the closed UI disappears in active uis but not in active resources.

Expected Behaviour

Also the resources are cleaned up.

Workaround
	@Override
	public void detach() {
		super.detach();
		getConnectorTracker().cleanConnectorMap(true);
	}
Runtime Environment

Vaadin Framework version: 8.9.3 (with compatibility classes)
Web container: Jetty 9.4.29

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with GlobalResourceHandler and the UI detachment lifecycle, then inspect where ConnectorTracker.cleanConnectorMap(true) is called. Reproduce the two-tab DemoUI scenario from the issue and compare active UIs with active resources after closing one tab. Done means resources associated with the detached or timed-out UI are removed without requiring the workaround in UI.detach().

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.