Skip to content

Commit 7cc032a

Browse files
committed
improve logging
1 parent fe25a32 commit 7cc032a

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ task runSimpleFileServer(type: Test) {
117117
dependsOn testClasses
118118
doLast {
119119
def props = systemProperties
120-
props.put("-Xshare","off")
121120
mkdir 'fileserver'
122121
javaexec {
123122
classpath sourceSets.test.runtimeClasspath

src/main/java/robaho/net/httpserver/ServerImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ public void run() {
293293
// we've hit max limit of current open connections, so we go
294294
// ahead and close this connection without processing it
295295
try {
296+
logger.log(Level.WARNING, "closing accepted connection due to too many connections");
296297
s.close();
297298
} catch (IOException ignore) {
298299
}
299-
// move on to next selected key
300300
continue;
301301
}
302302

@@ -334,8 +334,6 @@ public void run() {
334334
}
335335
}
336336

337-
static boolean debug = ServerConfig.debugEnabled();
338-
339337
Logger getLogger() {
340338
return logger;
341339
}
@@ -656,11 +654,14 @@ public void run() {
656654

657655
for (var c : allConnections) {
658656
if (currentTime - c.lastActivityTime >= IDLE_INTERVAL && !c.inRequest) {
657+
logger.log(Level.WARNING, "closing idle connection");
659658
closeConnection(c);
660659
// idle.add(c);
661660
} else if (c.noActivity && (currentTime - c.lastActivityTime >= NEWLY_ACCEPTED_CONN_IDLE_INTERVAL)) {
661+
logger.log(Level.WARNING, "closing newly accepted idle connection");
662662
closeConnection(c);
663663
} else if (MAX_REQ_TIME != -1 && c.inRequest && (currentTime - c.lastActivityTime >= MAX_REQ_TIME)) {
664+
logger.log(Level.WARNING, "closing connection due to request processing time");
664665
closeConnection(c);
665666
}
666667
// TODO is MAX_RSP_TIME needed?

src/test/extras/SimpleFileServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public static void main(String[] args) throws Exception {
6161
int port = Integer.parseInt(args[1]);
6262
String logfile = args[2];
6363
HttpServer server = HttpServer.create(new InetSocketAddress(port), 200);
64-
server.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
6564
HttpHandler h = new FileServerHandler(rootDir);
6665
HttpHandler h1 = new EchoHandler();
6766
HttpHandler h2 = new DevNullHandler();
@@ -75,7 +74,8 @@ public static void main(String[] args) throws Exception {
7574
HttpContext c2 = server.createContext("/devnull", h2);
7675
c2.getFilters().add(new LogFilter(new File(logfile)));
7776

78-
server.setExecutor(Executors.newCachedThreadPool());
77+
server.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
78+
// server.setExecutor(Executors.newCachedThreadPool());
7979
server.start();
8080
}
8181

0 commit comments

Comments
 (0)