Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Duplicate key detected in ClientRouteRegistry #2329

Closed
mshabarov opened this issue Apr 16, 2024 · 6 comments · Fixed by #2324
Closed

Duplicate key detected in ClientRouteRegistry #2329

mshabarov opened this issue Apr 16, 2024 · 6 comments · Fixed by #2324
Assignees
Labels
bug Something isn't working hilla Issues related to Hilla

Comments

@mshabarov
Copy link
Contributor

Describe the bug

I randomly get the runtime exception about duplicate key when Hilla tries to get all routes from ClientRouteRegistry:

java.lang.IllegalArgumentException: duplicate key: /about
        at java.base/java.util.ImmutableCollections$MapN.<init>(ImmutableCollections.java:1196) ~[na:na]
        at java.base/java.util.Map.ofEntries(Map.java:1680) ~[na:na]
        at java.base/java.util.Map.copyOf(Map.java:1748) ~[na:na]
        at com.vaadin.hilla.route.ClientRouteRegistry.getAllRoutes(ClientRouteRegistry.java:67) ~[hilla-endpoint-24.4.0.alpha21.jar:na]
        at com.vaadin.hilla.route.RouteUnifyingIndexHtmlRequestListener.collectClientViews(RouteUnifyingIndexHtmlRequestListener.java:115) ~[hilla-endpoint-24.4.0.alpha21.jar:na]
        at com.vaadin.hilla.route.RouteUnifyingIndexHtmlRequestListener.modifyIndexHtmlResponse(RouteUnifyingIndexHtmlRequestListener.java:82) ~[hilla-endpoint-24.4.0.alpha21.jar:na]

This prevents application to start.
Happens in both dev and prod modes, but quite randomly.

Expected-behavior

No duplicates in routes and no exception on startup.

Reproduction

This can be reproduced with the branch vaadin/flow-hilla-hybrid-example#29.

Download the starter, checkout the branch and start with mvn (or in production mode mvn spring-boot:run -Pproduction).

Reproduces randomly locally and in GHA. You need to try several times.

System Info

Vaadin 24.4.0.alpha21, Hilla 24.4.0.alpha21

@cromoteca
Copy link
Contributor

@mshabarov do you remember if this happens at startup or when making changes? I haven't been able to see it yet.

@mshabarov
Copy link
Contributor Author

I couldn't reproduce this issue anymore after removing the legacy views.ts.
However, it's unclear how this could help.
As we discussed with @taefi , it makes sense to:

  • use ConcurrentHashMap or such for registeredRoutes in ClientRouteRegistry or better
  • use synchronized for registerClientRoutes in RouteUnifyingIndexHtmlRequestListener and set lastUpdated as volatile, which makes it visible and eliminates registering routes concurrently.

@mshabarov
Copy link
Contributor Author

@mshabarov do you remember if this happens at startup or when making changes? I haven't been able to see it yet.

it happened to me in different two cases:

  • when starting an app in dev mode with mvn
  • when running IT tests in prod mode with mvn verify -Pit,production

Also happened several times in GHA when IT were running in prod mode.

@mshabarov
Copy link
Contributor Author

UPD: could reproduce it again with mvn verify -Pit,production

@cromoteca
Copy link
Contributor

I can't. Did you update your local branch to include my commit?

@mshabarov
Copy link
Contributor Author

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hilla Issues related to Hilla
Development

Successfully merging a pull request may close this issue.

3 participants