Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Push freezes UI when preserving UI on refresh. #12577

Closed
lennartfricke opened this issue Jan 30, 2023 · 3 comments
Closed

Push freezes UI when preserving UI on refresh. #12577

lennartfricke opened this issue Jan 30, 2023 · 3 comments
Labels
Milestone

Comments

@lennartfricke
Copy link
Contributor

Using the attached example code, refreshing the browser leads to infrequent freezes of the UI. The progress bar is shown and does not vanish.

package vaadin8_push;

import java.time.ZonedDateTime;

import com.vaadin.annotations.PreserveOnRefresh;
import com.vaadin.annotations.Push;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.communication.PushMode;
import com.vaadin.shared.ui.ui.Transport;
import com.vaadin.ui.Button;
import com.vaadin.ui.UI;

@Push(transport = Transport.LONG_POLLING, value = PushMode.MANUAL)
@PreserveOnRefresh
public class TestUI extends UI {

	private Thread bt;

	@Override
	protected void init(VaadinRequest request) {
		var time = new Button("Test");

		bt = new Thread(() -> {
			try {
				while (true) {
					this.access(() -> {
						time.setCaption(ZonedDateTime.now().toString());
						this.push();
					});
					Thread.sleep(500);
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		bt.setName("time-" + request.getWrappedSession().getId());
		bt.start();

		this.setContent(time);
	}

	@Override
	public void detach() {
		super.detach();
		bt.interrupt();
	}

}

The browser log shows:

Mon Jan 30 12:17:49 GMT+100 2023 com.vaadin.client.communication.MessageHandler
WARNING: Gave up waiting for message 51 from the server
Mon Jan 30 12:17:49 GMT+100 2023 com.vaadin.client.communication.MessageSender
INFO: Resynchronize from server requested

but no request is send, which can be seen from the network log of the browser.

Decreasing the sleep time makes the issue appear more often.
But increasing it to does not make it vanish completely, so that
I think that the browser is able to handle all responses in time.

We also experience infrequent freezes in our production code, even without refresh. But in that case there is proxy in between that might interrupt push long polling requests with gateway timeout responses, which might be related to the freezes.

I was hoping that the client side code is able to resynchronize when messages get lost.

Until this is fixed we need to revert to polling, which breaks session timeouts and automatic logout unfortunately.

Probably related: #7719

I can also upload the full source code for reference if you like.

  • Vaadin 8.19.0
  • Firefox 109 on linux
  • Embedded jetty 9.4.50
@mlindfors mlindfors added the BFP label Feb 2, 2023
@Ansku
Copy link
Member

Ansku commented Feb 2, 2023

On a quick glance this override to the UI class seems to help:

    @Override
    public void doRefresh(VaadinRequest request) {
        PushConnection pushConnection = getPushConnection();
        if (pushConnection instanceof AtmospherePushConnection
                && pushConnection.isConnected()) {
            pushConnection.disconnect();
        }
        super.doRefresh(request);
    }

This method is called when the UI is reinitialized, and closing the old connection here already (rather than later, when the new connection is ready to be registered) stops the Push from attempting to send more requests through the old connection and increasing the counter with every call while the new connection is still being initialized. I haven't run this solution through our validation builds yet, but at least my test project seems to behave better with it.

@Ansku Ansku closed this as completed Feb 7, 2023
@lennartfricke
Copy link
Contributor Author

I could not reproduce with 8.25.2 anymore. Even without workarounds

@TatuLund
Copy link
Contributor

TatuLund commented Aug 23, 2024

Yes, the fix was introduced in Vaadin 8.20, see:

https://github.com/vaadin/framework/blob/master/CHANGELOG-VAADIN8.md

@TatuLund TatuLund added this to the 8.20.0 milestone Aug 23, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants