Ensure the client watcher has been properly closed before handling its constructed...
authorFredrik Tolf <fredrik@dolda2000.com>
Fri, 18 Feb 2022 14:15:13 +0000 (15:15 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Fri, 18 Feb 2022 14:15:13 +0000 (15:15 +0100)
src/jagi/scgi/EventServer.java

index 2de2e86..202b8dd 100644 (file)
@@ -334,6 +334,7 @@ public class EventServer implements Runnable {
        int headlen = 0;
        ByteBuffer head = null;
        Map<Object, Object> env = null;
+       Request req = null;
 
        Client(SocketChannel sk) {
            this.sk = sk;
@@ -401,8 +402,7 @@ public class EventServer implements Runnable {
            if((events & SelectionKey.OP_READ) != 0) {
                if((env == null) && !readhead())
                    return;
-               Request req = new Request(env, sk);
-               submit(() -> EventServer.this.handle(req, handler));
+               req = new Request(env, sk);
                handoff = true;
            }
            if(Driver.current().time() > (lastread + timeout))
@@ -410,6 +410,8 @@ public class EventServer implements Runnable {
        }
 
        public void close() {
+           if(req != null)
+               submit(() -> EventServer.this.handle(req, handler));
            if(!handoff) {
                try {
                    sk.close();