Merge pull request #3853 from eclipse/jetty-10.0.x-3849-onError-abnormalClose

Issue #3849 - only notify onError for local errors
This commit is contained in:
Lachlan 2019-07-06 13:34:35 +10:00 committed by GitHub
commit 557b619fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 4 deletions

View File

@ -22,7 +22,6 @@ import java.io.IOException;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.nio.channels.ClosedChannelException;
import java.time.Duration;
import java.util.ArrayDeque;
import java.util.List;
@ -317,7 +316,7 @@ public class WebSocketCoreSession implements IncomingFrames, FrameHandler.CoreSe
connection.close();
// Forward Errors to Local WebSocket EndPoint
if (closeStatus.isAbnormal())
if (closeStatus.isAbnormal() && closeStatus.getCause() != null)
{
Callback errorCallback = Callback.from(() ->
{
@ -332,7 +331,7 @@ public class WebSocketCoreSession implements IncomingFrames, FrameHandler.CoreSe
}
});
Throwable cause = closeStatus.getCause() != null ? closeStatus.getCause() : new ClosedChannelException();
Throwable cause = closeStatus.getCause();
try
{
handler.onError(cause, errorCallback);

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.websocket.core.internal;
import java.nio.channels.ClosedChannelException;
import org.eclipse.jetty.websocket.core.CloseStatus;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
@ -133,7 +135,7 @@ public class WebSocketSessionState
default:
if (_closeStatus == null || CloseStatus.isOrdinary(_closeStatus.getCode()))
_closeStatus = new CloseStatus(CloseStatus.NO_CLOSE, "Session Closed");
_closeStatus = new CloseStatus(CloseStatus.NO_CLOSE, "Session Closed", new ClosedChannelException());
_sessionState = State.CLOSED;
return true;
}

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.core.proxy;
import java.io.IOException;
import java.net.URI;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
@ -281,6 +282,23 @@ class WebSocketProxy
if (LOG.isDebugEnabled())
LOG.debug("[{}] onClosed {}", toString(), closeStatus);
boolean abnormalClose = false;
synchronized (lock)
{
switch (state)
{
case CLOSED:
break;
default:
abnormalClose = true;
break;
}
}
if (abnormalClose)
server2Proxy.fail(new ClosedChannelException(), Callback.NOOP);
closed.countDown();
callback.succeeded();
}
@ -568,6 +586,24 @@ class WebSocketProxy
{
if (LOG.isDebugEnabled())
LOG.debug("[{}] onClosed {}", toString(), closeStatus);
boolean abnormalClose = false;
synchronized (lock)
{
switch (state)
{
case CLOSED:
break;
default:
abnormalClose = true;
break;
}
}
if (abnormalClose)
client2Proxy.fail(new ClosedChannelException(), Callback.NOOP);
closed.countDown();
callback.succeeded();
}