diff --git a/jetty-ee10/jetty-ee10-servlets/src/main/java/org/eclipse/jetty/ee10/servlets/EventSourceServlet.java b/jetty-ee10/jetty-ee10-servlets/src/main/java/org/eclipse/jetty/ee10/servlets/EventSourceServlet.java index 96914bb4395..7d1965886d7 100644 --- a/jetty-ee10/jetty-ee10-servlets/src/main/java/org/eclipse/jetty/ee10/servlets/EventSourceServlet.java +++ b/jetty-ee10/jetty-ee10-servlets/src/main/java/org/eclipse/jetty/ee10/servlets/EventSourceServlet.java @@ -29,6 +29,7 @@ import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.eclipse.jetty.util.ExceptionUtil; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.thread.AutoLock; @@ -211,8 +212,7 @@ public abstract class EventSourceServlet extends HttpServlet } catch (Throwable t) { - if (t != x) - x.addSuppressed(t); + ExceptionUtil.addSuppressedIfNotAssociated(x, t); getServletContext().log("failure", x); } } diff --git a/jetty-ee9/jetty-ee9-servlets/src/main/java/org/eclipse/jetty/ee9/servlets/EventSourceServlet.java b/jetty-ee9/jetty-ee9-servlets/src/main/java/org/eclipse/jetty/ee9/servlets/EventSourceServlet.java index b6028688497..70d2e68122c 100644 --- a/jetty-ee9/jetty-ee9-servlets/src/main/java/org/eclipse/jetty/ee9/servlets/EventSourceServlet.java +++ b/jetty-ee9/jetty-ee9-servlets/src/main/java/org/eclipse/jetty/ee9/servlets/EventSourceServlet.java @@ -29,6 +29,8 @@ import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.eclipse.jetty.util.ExceptionUtil; +import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.thread.AutoLock; /** @@ -202,8 +204,16 @@ public abstract class EventSourceServlet extends HttpServlet catch (IOException x) { // The other peer closed the connection - close(); - eventSource.onClose(); + IO.close(this::close); + try + { + eventSource.onClose(); + } + catch (Exception t) + { + ExceptionUtil.addSuppressedIfNotAssociated(x, t); + getServletContext().log("failure", x); + } } }