[NO ISSUE][OTH] Cancel queries on abrupt close of user connection
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Since there is no point of processing user queries when the user
disconnects before getting the response of their requests, the
QueryServiceServlet now cancels the user request when that happens.
Change-Id: I902b52322153d114f7ca5f0f06e0af9c5ead8f2a
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2490
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
index 5cbac64..3564736 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
@@ -47,7 +47,10 @@
import org.apache.hyracks.api.application.INCServiceContext;
import org.apache.hyracks.api.dataset.ResultSetId;
import org.apache.hyracks.api.job.JobId;
+import org.apache.hyracks.http.api.IChannelClosedHandler;
import org.apache.hyracks.http.api.IServletRequest;
+import org.apache.hyracks.http.server.HttpServer;
+import org.apache.hyracks.http.server.InterruptOnCloseHandler;
import org.apache.hyracks.ipc.exceptions.IPCException;
import org.apache.logging.log4j.Level;
@@ -160,4 +163,9 @@
super.handleExecuteStatementException(t, execution);
}
}
+
+ @Override
+ public IChannelClosedHandler getChannelClosedHandler(HttpServer server) {
+ return InterruptOnCloseHandler.INSTANCE;
+ }
}
diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/InterruptOnCloseHandler.java b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/InterruptOnCloseHandler.java
new file mode 100644
index 0000000..84b802f
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/InterruptOnCloseHandler.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.http.server;
+
+import java.util.concurrent.Future;
+
+import org.apache.hyracks.http.api.IChannelClosedHandler;
+import org.apache.hyracks.http.api.IServlet;
+
+public class InterruptOnCloseHandler implements IChannelClosedHandler {
+ public static final InterruptOnCloseHandler INSTANCE = new InterruptOnCloseHandler();
+
+ private InterruptOnCloseHandler() {
+ }
+
+ @Override
+ public void channelClosed(HttpServer server, IServlet servlet, Future<Void> task) {
+ task.cancel(true);
+ }
+
+}
diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpServerTest.java b/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpServerTest.java
index 7e6ccf4..71e84e5 100644
--- a/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpServerTest.java
+++ b/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpServerTest.java
@@ -33,6 +33,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hyracks.http.server.HttpServer;
+import org.apache.hyracks.http.server.InterruptOnCloseHandler;
import org.apache.hyracks.http.server.WebManager;
import org.apache.hyracks.http.server.utils.HttpUtil;
import org.apache.hyracks.http.servlet.ChattyServlet;
@@ -301,7 +302,7 @@
int numExecutors = 1;
int queueSize = 1;
HttpServer server = new HttpServer(webMgr.getBosses(), webMgr.getWorkers(), PORT, numExecutors, queueSize,
- (reqServer, reqServlet, reqTask) -> reqTask.cancel(true));
+ InterruptOnCloseHandler.INSTANCE);
SleepyServlet servlet = new SleepyServlet(server.ctx(), new String[] { PATH });
server.addServlet(servlet);
webMgr.add(server);