Changing Vaadin flow (14) basic configuration doesn't affect

Majid :

I'm using Vaadin Flow (14.1.18) and my question is a very bizarre behavior I've faced. I have added the following configs into my Spring Boot project's application.properties file.

// Expected behavior: Vaadin Client to send heartbeat to the server every second    
vaadin.heartbeatInterval=1
// Expected Behavior: Vaadin Server to close Idle sessions after 3 seconds (3 rounds of failed heart beats)
vaadin.closeIdleSessions=true

I have checked these configs to be applied practically on runtime using below code

DeploymentConfiguration deployConf = VaadinSession.getCurrent().getConfiguration();
int hbi =deployConf.getHeartbeatInterval();
boolean killIdle = deployConf.isCloseIdleSessions();
logger.info("Deployment Config >> KillIdleSessions : {} -- HeartBeatInterval : {}", killIdle, hbi);

And I get the following result which shows my configs got applied

2020-03-05 23:16:01.015 INFO 19224 --- [nio-9200-exec-3] com.package.sandbox.MainView : Deployment Config >> KillIdleSessions : true -- HeartBeatInterval : 1

But, the problem is, during the runtime, it seems Vaadin is ignoring all these configs, and despite I close the browser (UI instance won't be there anymore to send heartbeats) the session stays open indefinitely and never get closed (or destroyed, in Vaadin's perspective).

Erik Lumme :

The heartbeats are used to close other UIs in the session, it won't help in closing the last UI.

When the VaadinService has finished handling a request, it calls VaadinService#cleanupSession. This loops through all UIs in the session, and checks if the time passed since the last heartbeat is longer than three heartbeat intervals, in which case the UI is closed. The point of this is to clean up inactive UIs in the session, such as from closed tabs or refreshed windows.

When you close the last tab, the server will not receive any more requests for that session. As the cleanup code is run at the end of a request, it will not be triggered anymore. This prevents your last UI from being closed.

Instead, the session timeout comes into play. You can configure it with server.servlet.session.timeout, e.g. 120s or 2m. The embedded Tomcat has a reaper thread that is run once every minute, and it will close any inactive sessions. Note that with Spring, the minimum value for the session timeout is one minute.

If you leave a UI open but idle, the heartbeats will keep the session active, and prevent the session timeout handler form closing it. This is where closeIdleSessions comes into play. If it is set to true, after a request ends, Vaadin will check the last timestamp of a non-heartbeat request, and if the session timeout is exceeded, it will be closed by Vaadin.

So, in short

heartbeatInterval controls how quickly other inactive UIs in a session are closed, but does not affect the last UI.

closeIdleSessions controls whether or not heartbeats should prevent a session timing out for an otherwise idle UI.

Note: After changing values in application.properties, you might need an incognito window to test your changes, as the last session might've been serialized and re-used after a restart.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=27034&siteId=1