Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected Vaadin Session Expired and parallel spring boot applications

I am using Vaadin 8.9.4 and Spring boot 2.2.4.RELEASE. I have 2 spring boot applications, FirstApplication (server.port=8083) and SecondApplication (server.port=8084). Both the application have @SpringUI annotated class extending UI Class, as given below. The session for FirstApplication is expired as soon as I click on the button in the SecondApplication and vice versa. This happens only when I use two chorme tabs in parallel. If I use two different browsers, everything is working as expected.

Is this some kind of a bug as I expect no relation between the sessions of the two applications simply because they are running independently on different port.

Note: I am new to the spring boot and I am trying to build 2 micorservices communicating with each other via Rest API.

@SpringUI
@Theme("valo")
public class FirstApplicationUI extends UI {

    private static final long serialVersionUID = 9197592298697220144L;

    @Override
    protected void init(final VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        final Label label = new Label("First Application");
        final Button button = new Button("click");

        button.addClickListener(e -> Notification.show("First Application"));

        layout.addComponents(label, button);

        setContent(layout);
    }
}

@SpringUI
@Theme("valo")
public class SecondApplicationUI extends UI {

    private static final long serialVersionUID = 9059755286859361908L;

    @Override
    protected void init(final VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        final Label label = new Label("Second Application");
        final Button button = new Button("click");

        button.addClickListener(e -> Notification.show("Second Application"));

        layout.addComponents(label, button);

        setContent(layout);
    }
}
like image 348
Shobhit Avatar asked Nov 21 '25 20:11

Shobhit


1 Answers

This is your two applications battling over the same cookie; both use the same name and your browser happily sends both backends the same cookie as the port is not considered.

Change the name in at least one of your applications; see server.servlet.session.cookie.name in https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html

like image 78
cfrick Avatar answered Nov 24 '25 22:11

cfrick