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

Low level servlet request exception if connection is broken while loading a Vite resource #17995

Closed
Artur- opened this issue Nov 6, 2023 · 4 comments · Fixed by #18484
Closed

Comments

@Artur-
Copy link
Member

Artur- commented Nov 6, 2023

Description of the bug

  1. Create a new app npx @vaadin/cli init load
  2. Start it cd load && mvn
  3. Open in the browser and check the url vaadin-router is loaded from, e.g. http://localhost:8080/VAADIN/@fs/some-folder/load/node_modules/@vaadin/router/dist/vaadin-router.js?v=c742f5f9
  4. Put a breakpoint in StaticFileServer.serveStaticResource
  5. Run curl http://localhost:8080/VAADIN/@fs/some-folder/load/node_modules/@vaadin/router/dist/vaadin-router.js?v=c742f5f9
  6. Once the breakpoint is hit, press ctrl-c for the curl command
  7. Let the server continue

Then you see something like

2023-11-06T16:06:13.695+02:00 ERROR 81361 --- [io-8080-exec-10] c.vaadin.flow.server.StaticFileServer    : Unable to load /VAADIN/@fs/some-folder/load/node_modules/@vaadin/router/dist/vaadin-router.js from the frontend dev server: java.io.IOException: Broken pipe
2023-11-06T16:06:13.699+02:00 ERROR 81361 --- [io-8080-exec-10] o.a.c.c.C.[.[.[/].[springServlet]        : Servlet.service() for servlet [springServlet] threw exception

java.lang.IllegalStateException: Cannot create a session after the response has been committed
        at org.apache.catalina.connector.Request.doGetSession(Request.java:2907) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
        at org.apache.catalina.connector.Request.getSession(Request.java:2381) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
        at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:639) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
        at jakarta.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:221) ~[tomcat-embed-core-10.1.15.jar:6.0]

seems like sometimes the error is instead

java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
	at org.apache.catalina.connector.ResponseFacade.checkCommitted(ResponseFacade.java:485) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
	at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:329) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
	at jakarta.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:89) ~[tomcat-embed-core-10.1.15.jar:6.0]
	at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1528) ~[flow-server-24.2.2.jar:24.2.2]
	at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:398) ~[flow-server-24.2.2.jar:24.2.2]
	at com.vaadin.flow.spring.SpringServlet.service(SpringServlet.java:106) ~[vaadin-spring-24.2.2.jar:na]

Expected behavior

There is nothing in the log. The request for a static file was aborted. Nothing special about that.

Minimal reproducible example

As above

Versions

  • Vaadin / Flow version: 24.2.2
  • Java version: 21
  • OS version: macOs
@Artur-
Copy link
Member Author

Artur- commented Jan 18, 2024

This happens every now and then in my projects, does nobody else see it? The reproduction instructions here seem wrong though because I cannot reproduce it (anymore) with those and the "Unable to load... from the frontend dev server" sounds like it's a problem with the servlet <-> Vite connection and not user <-> servlet

@knoobie
Copy link
Contributor

knoobie commented Jan 18, 2024

I'm also seeing this quite often

@Artur-
Copy link
Member Author

Artur- commented Jan 18, 2024

I think the reason is this code

  try {
            if (devModeHandler != null
                    && !"/index.html".equals(filenameWithPath)
                    && devModeHandler.serveDevModeRequest(request, response)) {
                // We don't know what the dev server can serve, but if it served
                // something we are happy. There is always an index.html in the
                // dev server but we never want to serve that one directly.
                return true;
            }
        } catch (IOException e) {
            getLogger().error("Unable to load " + filenameWithPath
                    + " from the frontend dev server: " + e.getMessage());
        }

where Flow is catching an IOException coming from writing the vite server response to the disconnected client but not aborting handling the request

@Artur-
Copy link
Member Author

Artur- commented Jan 18, 2024

So probably the real error is somewhere before those exceptions in the log as the exceptions only tell that we cannot continue to serve index.html to a request that was already closed

mshabarov pushed a commit that referenced this issue Jan 22, 2024
…18484)

If the failure comes from writing to the original request (e.g. because client has closed/aborted the connection), then we cannot continue trying to write another response to it. If the failure comes from the connection to the Vite server, we still don't know if it would have served a resource or not so we should abort.

Fixes #17995 

Does not fix the underlying cause for the connection being aborted though but #17995 does not have information about that
@github-project-automation github-project-automation bot moved this from 🔖 Normal Priority (P2) to ✅ Closed in Vaadin Flow bugs & maintenance (Vaadin 10+) Jan 22, 2024
vaadin-bot pushed a commit that referenced this issue Jan 22, 2024
…18484)

If the failure comes from writing to the original request (e.g. because client has closed/aborted the connection), then we cannot continue trying to write another response to it. If the failure comes from the connection to the Vite server, we still don't know if it would have served a resource or not so we should abort.

Fixes #17995 

Does not fix the underlying cause for the connection being aborted though but #17995 does not have information about that
vaadin-bot added a commit that referenced this issue Jan 22, 2024
…18484) (#18507)

If the failure comes from writing to the original request (e.g. because client has closed/aborted the connection), then we cannot continue trying to write another response to it. If the failure comes from the connection to the Vite server, we still don't know if it would have served a resource or not so we should abort.

Fixes #17995 

Does not fix the underlying cause for the connection being aborted though but #17995 does not have information about that

Co-authored-by: Artur <artur@vaadin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

3 participants