Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin "A connector with id xy is already registered"

Tags:

vaadin

Somewhere in my Vaadin application, I'm getting this exception as soon as I connect using a second browser

Caused by: java.lang.RuntimeException: A connector with id 22 is already registered! at com.vaadin.ui.ConnectorTracker.registerConnector(ConnectorTracker.java:133)

It happens always in the same place but I don't know why exactly as the reason for this must be somewhere else.

I think I might be stealing UI components from the other session - which is not my intention. Currently, I don't see any static instances of UI components I might be using in multiple sessions.

How can I debug this? It's become quite a large project. Any hints to look for?

like image 584
Atmocreations Avatar asked May 27 '14 05:05

Atmocreations


3 Answers

Here is how I fixed it -

1) look for components you have shared across sessions. For example if you have declared a component as static it will be created once and will be shared.

2) if you are not able to find it and want a work around until you figure out the real problem, put your all addComponent calls in try and in catch add following code -

getUI().getConnectorTracker().markAllConnectorsDirty();
getUI().getConnectorTracker().markAllClientSidesUnititialized();
getPage().reload():

This will clear old connectors and will reload the page properly only when it fails. For me it was failing when I was logged out and logged in back.

Once you find the real problem you can fix it till then inform your customers about the reload.

**** note - only solution is to remove shared components this is just a work around.

like image 175
Sandy Avatar answered Nov 13 '22 13:11

Sandy


I think I might be stealing UI components from the other session - which is not my intention. Currently, I don't see any static instances of UI components I might be using in multiple sessions.

That was it. I was actually stealing UI components without prior knowledge.

It was very well hidden in a part which seems to be same for all instances. Which is true: the algorithm is the same.

Doesn't mean I should've reused the same UI components as well...

Thanks to those who took a closer look.

like image 33
Atmocreations Avatar answered Nov 13 '22 11:11

Atmocreations


Yes, this usually happens because you are attaching a component already attached in other session.

Try logging the failed connector with a temporal ConnectorTracker, So the next time that it happens, you can catch it.

For example:

public class SomeUI extends UI {

  private ConnectorTracker tracker;

  @Override
  public ConnectorTracker getConnectorTracker() {
    if (this.tracker == null) {
      this.tracker =  new ConnectorTracker(this) {

        @Override
        public void registerConnector(ClientConnector connector) {
          try {
            super.registerConnector(connector);
          } catch (RuntimeException e) {
            getLogger().log(Level.SEVERE, "Failed connector: {0}", connector.getClass().getSimpleName());
            throw e;
          }
        }

      };
    }

    return tracker;
  }
}
like image 6
Jose Luis Martin Avatar answered Nov 13 '22 12:11

Jose Luis Martin