Short description of the situation: while clicking a Vaadin button the Vaadin Heartbeat evaluation is blocked by a lock at the session. When the execution of a button action takes more than 3 heartbeat-intervals then the connection is lost.
Short question: is there a way to keep the heartbeat going even if the button click execution takes more than 3 heartbeat-intervals?
More detailed description of the situation: In a Vaadin 8.8.6 application I have this situation (and the relevant code seems not to have changed up to 14.6.9 and maybe beyond that):
The cause for the server to close the session is that the com.vaadin.server.communication.HeartbeatHandler
hadn't got a heartbeat message for about 15 minutes (=3x5 minutes = 3x heartbeat interval).
And the server hadn't got a heartbeat message for 15 minutes because in com.vaadin.server.SynchronizedRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse)
there is a lock at the session (it's the same object with the same ID for the heartbeat request and for the button executing request).
Workaround A: Setting the heartbeat interval to 10 minutes gives the button a range of 3x10 = 30 minutes to execute.
Workaround B: Modifying the HeartbeatHandler class and disabling the session locking by overriding the method handleRequest (and doing this also for UnsupportedBrowserHandler
, SessionRequestHandler
and VaadinService.findOrCreateVaadinSession
(this is the one I'm feeling not comfortable about changing)):
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request,
VaadinResponse response) throws IOException {
if (!canHandleRequest(request)) {
return false;
}
// ## This is part of the relevant change
// session.lock();
try {
return synchronizedHandleRequest(session, request, response);
} finally {
// ## This is part of the relevant change
// session.unlock();
}
}
Workaround C: Executing every button asynchronously. This seems to be a lot of effort as there are many buttons in that application.
Question: Is there a more standardized way in Vaadin to keep the Heartbeat going (and keep the session alive) even if there is a seldom button execution taking more than 3x default heartbeat interval (=3x 5 minutes)?
As Andre said, Workaround C is the correct way to do. I would not even call it workaround, but the thing you just need to do. Also noting, Workaround B is absolutely wrong, and will break things. Workaround A, yes heart beat is adjustable, but not purposed for this. It is often the opposite need, i.e. make it shorter to make server drop abandoned UI's more aggressively and hence reducing resources reserved for them.