Skip to content

Commit 9c4667a

Browse files
committed
Close websocket session explicitly on EOFException
1 parent 62a23e3 commit 9c4667a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/java/graphql/servlet/GraphQLWebsocketServlet.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.websocket.*;
88
import javax.websocket.server.HandshakeRequest;
99
import javax.websocket.server.ServerEndpointConfig;
10+
import java.io.EOFException;
1011
import java.io.IOException;
1112
import java.util.Collections;
1213
import java.util.HashMap;
@@ -99,8 +100,13 @@ public void onClose(Session session, CloseReason closeReason) {
99100

100101
@Override
101102
public void onError(Session session, Throwable thr) {
102-
log.error("Error in websocket session: {}", session.getId(), thr);
103-
closeUnexpectedly(session, thr);
103+
if (thr instanceof EOFException) {
104+
log.warn("Session {} was killed abruptly without calling onClose. Cleaning up session", session.getId());
105+
onClose(session, ERROR_CLOSE_REASON);
106+
} else {
107+
log.error("Error in websocket session: {}", session.getId(), thr);
108+
closeUnexpectedly(session, thr);
109+
}
104110
}
105111

106112
private void closeUnexpectedly(Session session, Throwable t) {

0 commit comments

Comments
 (0)