Skip to content

Commit 0646f88

Browse files
committed
Send a message on startup, increase the timeout, and stop sending later calls
This is a followup to the original bug report to emphasize that Jetty 12 is failing to notify the servlet and its listeners that the client is definitely gone. Further, it calls out that 12+ee10 does not notify on timeouts.
1 parent 1478f45 commit 0646f88

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

jetty-11/src/main/java/com/example/jetty11/Server.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public static void main(String[] args) throws Exception {
3333
context.addServlet(new ServletHolder(servlet), "/connect");
3434
s.setHandler(context);
3535

36-
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
37-
executorService.scheduleAtFixedRate(() -> {
38-
try {
39-
servlet.sayHi();
40-
} catch (Exception e) {
41-
// log and continue
42-
LOG.warn("Error writing in exec service", e);
43-
}
44-
}, 1, 1, TimeUnit.SECONDS);
36+
// ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
37+
// executorService.scheduleAtFixedRate(() -> {
38+
// try {
39+
// servlet.sayHi();
40+
// } catch (Exception e) {
41+
// // log and continue
42+
// LOG.warn("Error writing in exec service", e);
43+
// }
44+
// }, 1, 1, TimeUnit.SECONDS);
4545

4646
s.start();
4747
s.join();

jetty-12/ee10/src/main/java/com/example/jetty12/ee10/Server.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public static void main(String[] args) throws Exception {
3333
context.addServlet(new ServletHolder(servlet), "/connect");
3434
s.setHandler(context);
3535

36-
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
37-
executorService.scheduleAtFixedRate(() -> {
38-
try {
39-
servlet.sayHi();
40-
} catch (Exception e) {
41-
// log and continue
42-
LOG.warn("Error writing in exec service", e);
43-
}
44-
}, 1, 1, TimeUnit.SECONDS);
36+
// ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
37+
// executorService.scheduleAtFixedRate(() -> {
38+
// try {
39+
// servlet.sayHi();
40+
// } catch (Exception e) {
41+
// // log and continue
42+
// LOG.warn("Error writing in exec service", e);
43+
// }
44+
// }, 1, 1, TimeUnit.SECONDS);
4545

4646
s.start();
4747
s.join();

jetty-12/ee9/src/main/java/com/example/jetty12/ee9/Server.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public static void main(String[] args) throws Exception {
3333
context.addServlet(new ServletHolder(servlet), "/connect");
3434
s.setHandler(context);
3535

36-
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
37-
executorService.scheduleAtFixedRate(() -> {
38-
try {
39-
servlet.sayHi();
40-
} catch (Exception e) {
41-
// log and continue
42-
LOG.warn("Error writing in exec service", e);
43-
}
44-
}, 1, 1, TimeUnit.SECONDS);
36+
// ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
37+
// executorService.scheduleAtFixedRate(() -> {
38+
// try {
39+
// servlet.sayHi();
40+
// } catch (Exception e) {
41+
// // log and continue
42+
// LOG.warn("Error writing in exec service", e);
43+
// }
44+
// }, 1, 1, TimeUnit.SECONDS);
4545

4646
s.start();
4747
s.join();

servlet/src/main/java/com/example/servlet/AsyncStreamingServlet.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,14 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
127127
@Override
128128
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
129129
AsyncContext asyncCtx = req.startAsync(req, resp);
130-
asyncCtx.setTimeout(10_000);
130+
asyncCtx.setTimeout(100_000);
131131

132132
final int id = nextId.getAndIncrement();
133133

134134
LOG.info("New request #" + id);
135135

136136
ClientConnection c = new ClientConnection(id, asyncCtx);
137+
c.println("startup");
137138
connections.add(c);
138139
}
139140

0 commit comments

Comments
 (0)