cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject git commit: [CXF-6075] NPE may occur at websocket destination under high load
Date Fri, 31 Oct 2014 12:53:20 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes f46a9bcb9 -> dc7873b1c


[CXF-6075] NPE may occur at websocket destination under high load


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/dc7873b1
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/dc7873b1
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/dc7873b1

Branch: refs/heads/3.0.x-fixes
Commit: dc7873b1c7fda96eead98bcef04864935f39f550
Parents: f46a9bc
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Fri Oct 31 13:49:12 2014 +0100
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Fri Oct 31 13:52:40 2014 +0100

----------------------------------------------------------------------
 .../atmosphere/AtmosphereWebSocketHandler.java      | 16 ++++++++++++++--
 .../transport/websocket/jetty/JettyWebSocket.java   | 16 ++++++++++++++--
 2 files changed, 28 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/dc7873b1/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketHandler.java
----------------------------------------------------------------------
diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketHandler.java
b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketHandler.java
index 776741e..38e6599 100644
--- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketHandler.java
+++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketHandler.java
@@ -27,6 +27,7 @@ import java.security.Principal;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Locale;
+import java.util.concurrent.RejectedExecutionException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -99,11 +100,11 @@ public class AtmosphereWebSocketHandler implements WebSocketProtocol
{
     
     protected List<AtmosphereRequest> invokeService(final WebSocket webSocket,  final
InputStream stream) {
         LOG.fine("invokeService(WebSocket, InputStream)");
-        // invoke the service directly as onMessage is synchronously blocked (in jetty)
+        // invoke the service asynchronously as onMessage is synchronously blocked (in jetty)
         // make sure the byte array passed to this method is immutable, as the websocket
framework
         // may corrupt the byte array after this method is returned (i.e., before the data
is returned in
         // the executor's thread.
-        destination.getExecutor().execute(new Runnable() {
+        executeServiceTask(new Runnable() {
             @Override
             public void run() {
                 HttpServletRequest request = null;
@@ -131,6 +132,17 @@ public class AtmosphereWebSocketHandler implements WebSocketProtocol
{
         return null;
     }
 
+    private void executeServiceTask(Runnable r) {
+        try {
+            destination.getExecutor().execute(r);
+        } catch (RejectedExecutionException e) {
+            LOG.warning(
+                "Executor queue is full, run the service invocation task in caller thread."

+                + "  Users can specify a larger executor queue to avoid this.");
+            r.run();
+        }
+    }
+    
     // may want to move this error reporting code to WebSocketServletHolder
     protected void reportErrorStatus(HttpServletResponse response, int status) {
         if (response != null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/dc7873b1/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocket.java
----------------------------------------------------------------------
diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocket.java
b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocket.java
index 5bab332..6ae3c9f 100644
--- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocket.java
+++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocket.java
@@ -28,6 +28,7 @@ import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.concurrent.RejectedExecutionException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -109,7 +110,7 @@ class JettyWebSocket implements WebSocket.OnBinaryMessage, WebSocket.OnTextMessa
         // make sure the byte array passed to this method is immutable, as the websocket
framework
         // may corrupt the byte array after this method is returned (i.e., before the data
is returned in
         // the executor's thread.
-        manager.getExecutor().execute(new Runnable() {
+        executeServiceTask(new Runnable() {
             @Override
             public void run() {
                 HttpServletRequest request = null;
@@ -133,7 +134,18 @@ class JettyWebSocket implements WebSocket.OnBinaryMessage, WebSocket.OnTextMessa
             }
         });
     }
-    
+
+    private void executeServiceTask(Runnable r) {
+        try {
+            manager.getExecutor().execute(r);
+        } catch (RejectedExecutionException e) {
+            LOG.warning(
+                "Executor queue is full, run the service invocation task in caller thread."

+                + "  Users can specify a larger executor queue to avoid this.");
+            r.run();
+        }
+    }
+
     // may want to move this error reporting code to WebSocketServletHolder
     private void reportErrorStatus(HttpServletResponse response, int status) {
         if (response != null) {


Mime
View raw message