Invalidating sessions

Hello! I want to invalidate the current user sessions and navigate to a route, how do I do this without getting a Illegal State Exception?

VaadinSession.getCurrent().getSession().invalidate();
        VaadinSession.getCurrent().close();
        UI.getCurrent().getPage().setLocation("login");

You do not need to call close, invalidating the session will close it by itself.