Cancel container activation onBeforeUnload

#1

Hi!
When a user starts a container (for instance by clicking a link) and rapidly closes the tab, the proxy gets activated and it continues to live until heartbeat-timeout is reached.
I have a very large heartbeat timeout, as I rely on the API within R to stop the containers (onSessionEnded()). As, by closing the tab, the user does not start a shiny session, the R code for reaching the API is not executed.
Therefore, I can have several unused containers using RAM unnecessarily during hours.

Would it be possible to cancel the proxy activation, eg. when the users closes the browser’s tab?
Best

#2

Another possibility would be to rely on heartbeat mechanism (if no heartbeat is received within the first minute following the start of the container, shinyproxy stops it).

#3

Here is the code related to this (line 174 of file HeartbeatService.java from ContainerProxy). Would you be interested in a pull request?

if (lastHeartbeat == null) {
	if (currentTimestamp - proxy.getStartupTimestamp() > 60000){
		log.info(String.format("Releasing proxy without Heartbeat [spec: %s] [id: %s]", proxy.getSpec().getId(), proxy.getId()));
		proxyHeartbeats.remove(proxy.getId());
		proxyService.stopProxy(proxy, true, true);
		return;
	}
	lastHeartbeat = proxy.getStartupTimestamp();
}

Best

1 Like