`UI` being instantiated over and over again in default Vaadin 14.0.1 app

Any update on this? In Vaadin 7, I could logout and cycle through UI to do special logout activity for each UI, but now, because of the multiple UI instances, even for one tab,my code is quite confused. In other words, on logout, I expect only one UI because only 1 tab open, but I see 2-4 UI.

Anthony Baldarelli:
Any update on this? In Vaadin 7, I could logout and cycle through UI to do special logout activity for each UI, but now, because of the multiple UI instances, even for one tab,my code is quite confused. In other words, on logout, I expect only one UI because only 1 tab open, but I see 2-4 UI.

Looking at [Leif’s answer]
(https://github.com/vaadin/flow/issues/6321#issuecomment-527957755) to the first ticket, you’ll see that multiple UIs may be created initially when a stray service worker sends requests that result in a 404.

If you haven’t had @PWA and then removed it, only one UI will be created. However, refreshing the page or otherwise navigating without using RouterLink or UI.navigate will result in a new UI being created, as I believe it used to work in Vaadin 7 and 8 also.

Note that old UI’s detach after missing three heartbeats, where the standard heartbeat interval I think is 5 minutes.

If the issue is with @PreserveOnRefresh, there’s an issue here https://github.com/vaadin/flow/issues/6395

OK, this is what I did: I started the application in the eclipse debugger and just waited, did not touch the browser at all, no human actions. I just have a breakpoint in my UIInitListener:

public class WmsServiceInitListener implements VaadinServiceInitListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1029506952956361276L;
	private static final Logger LOGGER = Logger.getLogger(WmsServiceInitListener.class.getName());

	@Override
	public void serviceInit(ServiceInitEvent event) {
		event.getSource().addUIInitListener(ue -> {
			LOGGER.info(
					"Starting new UI: WMS session/UI " + VaadinSession.getCurrent() + "/" + ue.getUI() );
		});
		
		event.getSource().addSessionDestroyListener(new WmsSessionDestroyListener());
		event.getSource().addSessionInitListener(new WmsSessionInitListener());
	}

}

I also have a breakpoint in sessionInit method of my WmsSessionInitListener. With or without @PreserveOnRefresh enabled ( I never enabled it for Vaadin 7 because I did not need it ), I keep hitting my uiInitListener breakpoint. Note that I am doing nothing, at least not as a user. I am not currently using @PWA, since I don’t need it yet and my MPR + Vaadin 7 app is not ready for it at all. Here is the logging ( I cut out some portions of lines, but left every line of logging to show timing of events ). Why is it initializing the UI even though I am doing nothing? You mention service workers, but to the best of my knowledge I don’t have one. How can I prove that true or false?

[INFO]
 Started Jetty Server
19-09-10 17:13:00:489  WARN qtp1122084462-30 server.DefaultDeploymentConfiguration:242 - 
====================================================================
Vaadin is running in DEBUG MODE.
Add productionMode=true to web.xml to disable debug features.
====================================================================
Sep 10, 2019 5:13:19 PM com.mobiwms.website.WmsSessionInitListener sessionInit INFO: Initializing session com.vaadin.flow.server.VaadinSession@5ed864e4 with 0 UIs
Sep 10, 2019 5:13:25 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@5ed864e4/com.vaadin.flow.component.UI@78fafb66
Sep 10, 2019 5:13:26 PM com.mobiwms.website.WmsEntryPoint <init> INFO: Starting WMS session/UI com.vaadin.flow.server.VaadinSession@5ed864e4/com.vaadin.flow.component.UI@78fafb66
Sep 10, 2019 5:13:26 PM com.mobiwms.website.WmsEntryPoint <init> INFO: Flow version '2.0.10', platform version '14.0.3', vaadin7 version '7.7.17', project version '3.8.Merge-vaadin14.0.3'
Sep 10, 2019 5:13:26 PM com.mobiwms.website.WmsEntryPoint <init> INFO: Browser/computer info: browser is Chrome, IP 0:0:0:0:0:0:0:1, OS Windows
Sep 10, 2019 5:13:26 PM com.mobiwms.website.WmsEntryPoint INFO: 4 servlet registrations.
Sep 10, 2019 5:13:26 PM com.wmsvision.util.ServletUtils logContextServlets INFO: Servlet name: default (org.eclipse.jetty.servlet.DefaultServlet); Mappings: /
Sep 10, 2019 5:13:26 PM com.wmsvision.util.ServletUtils logContextServlets INFO: Servlet name: jsp (org.eclipse.jetty.jsp.JettyJspServlet); Mappings: *.jsp, *.jspf, *.jspx, *.xsp, *.JSP, *.JSPF, *.JSPX, *.XSP
Sep 10, 2019 5:13:26 PM com.wmsvision.util.ServletUtils logContextServlets INFO: Servlet name: com.vaadin.mpr.MprServlet; Mappings: /framework/*
Sep 10, 2019 5:13:26 PM com.wmsvision.util.ServletUtils logContextServlets INFO: Servlet name: com.vaadin.flow.server.startup.ServletDeployer (com.vaadin.flow.server.VaadinServlet); Mappings: /*
Sep 10, 2019 5:13:26 PM com.mobiwms.website.component.HelpVideoWindow <init> INFO: Title: Login; ...
Sep 10, 2019 5:13:26 PM com.mobiwms.website.component.HelpVideoWindow getWmsHelpVideo INFO: Title: Login; Video name: null
Sep 10, 2019 5:13:26 PM com.mobiwms.website.component.HelpVideoWindow getWmsHelpVideoByTitle INFO: Title: Login; videoDirectory: null
Sep 10, 2019 5:13:26 PM com.mobiwms.website.component.HelpVideoWindow getWmsHelpVideoByTitle INFO: Title: Login; videoDirectory: null
Sep 10, 2019 5:13:26 PM com.mobiwms.website.domain.MessageMgmtService getInstance WARNING: No MessageMgmtService in WmsUI data provider, so trying session
Sep 10, 2019 5:13:26 PM com.mobiwms.website.view.login.LoginView <init> INFO: Got message mgmt service for holiday footer.
Sep 10, 2019 5:13:26 PM com.mobiwms.website.domain.LoginService getInstance WARNING: com.vaadin.flow.server.VaadinSession@5ed864e4/com.vaadin.flow.component.UI@78fafb66: No LoginService in WmsEntryPoint data provider, so trying session
Sep 10, 2019 5:13:26 PM com.wmsvision.web.util.WebConfig getClientSocket INFO: Get socket for client: mobiwms
Sep 10, 2019 5:13:26 PM com.wmsvision.web.util.WebConfig getWmsConfPath INFO: Path 1 ...
Sep 10, 2019 5:13:26 PM com.wmsvision.web.util.WebConfig getWmsConfPath INFO: Path 2 ...
Sep 10, 2019 5:13:26 PM com.wmsvision.web.util.WebConfig getWmsConfPath INFO: Path 3 ...
Sep 10, 2019 5:13:26 PM com.wmsvision.web.util.WebConfig getWmsConfPath INFO: Getting configuration from ...
Sep 10, 2019 5:13:26 PM com.wmsvision.web.util.WebConfig getClientSocket INFO: Name 'socket.xml';Path '...'
Sep 10, 2019 5:13:26 PM com.wmsvision.web.util.WebConfig getClientSocket SEVERE: Configuration file (socket.xml) missing.
Sep 10, 2019 5:13:26 PM com.wmsvision.web.WebClientSocket getInstance WARNING: Ignored WebClientSock exception java.io.FileNotFoundException: D:\...\vaadinwebsite\src\conf\wms\socket.xml (The system cannot find the path specified): D:\...\vaadinwebsite\src\conf\wms\socket.xml (The system cannot find the path specified)
Sep 10, 2019 5:13:26 PM com.mobiwms.website.domain.LoginService getInstance INFO: com.vaadin.flow.server.VaadinSession@5ed864e4/com.vaadin.flow.component.UI@78fafb66: Getting new login service, created at Tue Sep 10 17:13:26 EDT 2019
Sep 10, 2019 5:13:26 PM com.mobiwms.website.data.WmsDataProvider setLoginService INFO: com.vaadin.flow.server.VaadinSession@5ed864e4/com.vaadin.flow.component.UI@78fafb66: Setting login service to com.mobiwms.website.domain.LoginService@50304d18
Sep 10, 2019 5:13:26 PM com.mobiwms.website.domain.LoginService getInstanceClient SEVERE: No client for login session created at Tue Sep 10 17:13:26 EDT 2019, so get a new client, forcing a refresh
Sep 10, 2019 5:13:26 PM com.wmsvision.web.util.WebConfig getClientSocket INFO: Get socket for client: mobiwms
Sep 10, 2019 5:13:26 PM com.wmsvision.web.util.WebConfig getClientSocket INFO: Name 'socket.xml';Path '...'
Sep 10, 2019 5:13:26 PM com.wmsvision.web.util.WebConfig getClientSocket SEVERE: Configuration file (socket.xml) missing.
Sep 10, 2019 5:13:26 PM com.wmsvision.web.WebClientSocket getInstance WARNING: Ignored WebClientSock exception java.io.FileNotFoundException: D:\...\vaadinwebsite\src\conf\wms\socket.xml (The system cannot find the path specified): D:\...\vaadinwebsite\src\conf\wms\socket.xml (The system cannot find the path specified)
Sep 10, 2019 5:13:26 PM com.mobiwms.website.domain.LoginService getInstanceClient INFO: Got login service, created at Tue Sep 10 17:13:26 EDT 2019, with no client
Sep 10, 2019 5:13:26 PM com.mobiwms.website.view.login.LoginView <init> SEVERE: Backend seems to be down: Test webClient down
Sep 10, 2019 5:13:31 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@5ed864e4/com.vaadin.flow.component.UI@6d92f062
Sep 10, 2019 5:15:15 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@5ed864e4/com.vaadin.flow.component.UI@539b01ac
Sep 10, 2019 5:18:43 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@5ed864e4/com.vaadin.flow.component.UI@271e8d0b
Sep 10, 2019 5:20:20 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@5ed864e4/com.vaadin.flow.component.UI@13651aa0
Sep 10, 2019 5:23:51 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@5ed864e4/com.vaadin.flow.component.UI@690376f3

More info, a little bit clearer logging. Note how the session does not change, but the number of UIs keeps increasing. Except for the generic website stuff I snipped out to make it briefer, this is the exact order of events. When the number of UIs went from 2 to 7, I was not even looking at the web page, I was looking at Eclipse, trying to find places that could be triggering new UIs by accident.

Sep 10, 2019 7:42:43 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@60d47c7b/com.vaadin.flow.component.UI@735634c6 with 1 UIs.
Sep 10, 2019 7:42:43 PM com.mobiwms.website.WmsEntryPoint <init> INFO: Starting WMS session/UI com.vaadin.flow.server.VaadinSession@60d47c7b/com.vaadin.flow.component.UI@735634c6
... /* some website stuff */
19-09-10 19:42:43:987  WARN qtp1278339302-191 communication.PushHandler:84 - Invalid identifier in new connection received from 0:0:0:0:0:0:0:1
Sep 10, 2019 7:42:46 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@60d47c7b/com.vaadin.flow.component.UI@5c5c75e2 with 2 UIs.
Sep 10, 2019 7:43:31 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@60d47c7b/com.vaadin.flow.component.UI@3f6d51c4 with 3 UIs.
Sep 10, 2019 7:47:44 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@60d47c7b/com.vaadin.flow.component.UI@b280d8a with 4 UIs.
Sep 10, 2019 7:48:45 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@60d47c7b/com.vaadin.flow.component.UI@1fbaf2d7 with 5 UIs.
Sep 10, 2019 7:52:44 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@60d47c7b/com.vaadin.flow.component.UI@7c898701 with 6 UIs.
Sep 10, 2019 7:53:15 PM com.mobiwms.website.WmsServiceInitListener lambda$0 INFO: Starting new UI: WMS session/UI com.vaadin.flow.server.VaadinSession@60d47c7b/com.vaadin.flow.component.UI@1e43a788 with 7 UIs.

For service workers, in Chrome you can open the developer tools, go to the “Application” tab, and then to “Service Workers” to see if any are present.

In the network tab of your browser developer tools, what requests are sent when the new UIs are created?

Thanks, it is sw.js, and chrome says it is failing for some reason. Looking at the “Console” at the same time, I see a “A bad HTTP response code (404) was received when fetching the script.” I wonder if that is why it keeps trying to create new UIs. No idea why it is happening, but at least this explains what is happening. I closed down the corresponding Chrome tab ( so not the full browser window, just the tab ), waited 5 minutes. After 5 minutes, no new UIs. This makes sense since it seems something on Chrome side was requesting the new UIs, and this matches the docs. Just wanted to confirm it.

For MS Edge, I don’t see this behavior after waiting 5-7 minutes. I am using the exact same Eclipse debug session as above. Total side note, but Edge has less problems than Chrome, which is surprising.

Tried IE, and I don’t see this behavior after waiting 5-8 minutes.

Tried Firefox, and I did see this behavior, but in this case the old Chrome session was finally destroyed ( timed out ). So I stopped debugger, and restarted application in debugger. I waited about 20 minutes with no problems.

Alright, sounds like we’ve got a plausible reason for this issue. It’s possible that the service worker hasn’t been registered on IE or Edge, and that’s why the behavior is different. IE11 does not even support them.

Note that service workers are specific to browser and domain. Unfortunately this means that if you’ve opened an app that uses service workers on localhost:8080, they will also be around when you load a completely different app on the same URL. As such, the service worker might come from somewhere else.

It might help to check “Bypass for network” in the service workers tab, it’s also safe to unregister any service workers you might have. If they are not coming from the current app, they won’t reappear when reloading the page.

OK, thanks. That helped a lot.

Ironically enough, I had to reboot my machine last night, which meant I had to totally restart Chrome. Now it does not happen. I actually never used a fresh instance of Chrome above, kept using same session of Chrome to test multiple localhost applications, all of which are Vaadin based ( I was playing with the business app demo last week ). I bet one of those did the service work stuff, and restarting Chrome might have fixed it/clear it. In fact, oftentimes if I was not running the app in eclipse, the business app “cannot connect” page would come up in my Chrome browser window. So next time, I will try a Chrome restart first. If that does not work, I will try your advice above.

Basil Bourque:

Syam Pillai:
No, web browsers do not invoke web pages while typing other than showing entries from the cache.

Incorrect.

Typing an “l” (for localhost) in Safari web browser’s URL address bar causes my Vaadin app to run a new session, with output on the console. This happens in the background, with no Vaadin app yet loaded into the browser window.

See screenshot attached.

And try it for yourself.

AFAIK the load you see when typing “l” in Safaris search bar might very be explained by the preload (which, I assume, is run in a different session that the current session). Still doesnt explain the other session issues.

https://support.apple.com/guide/safari/customize-searching-ibrwe75c2a3c/mac