Skip to content

Commit 09cb7f4

Browse files
committed
Fine-tuned logging of WebSocket close exceptions
Issue: SPR-16409 (cherry picked from commit 8e2be91)
1 parent 04f9549 commit 09cb7f4

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -119,8 +119,8 @@ public void onWebSocketClose(int statusCode, String reason) {
119119
this.webSocketHandler.afterConnectionClosed(this.wsSession, closeStatus);
120120
}
121121
catch (Throwable ex) {
122-
if (logger.isErrorEnabled()) {
123-
logger.error("Unhandled error for " + this.wsSession, ex);
122+
if (logger.isWarnEnabled()) {
123+
logger.warn("Unhandled exception after connection closed for " + this, ex);
124124
}
125125
}
126126
}

spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketHandlerAdapter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -141,8 +141,8 @@ public void onClose(javax.websocket.Session session, CloseReason reason) {
141141
this.handler.afterConnectionClosed(this.wsSession, closeStatus);
142142
}
143143
catch (Throwable ex) {
144-
if (logger.isErrorEnabled()) {
145-
logger.error("Unhandled error for " + this.wsSession, ex);
144+
if (logger.isWarnEnabled()) {
145+
logger.warn("Unhandled on-close exception for " + this.wsSession, ex);
146146
}
147147
}
148148
}

spring-websocket/src/main/java/org/springframework/web/socket/handler/ExceptionWebSocketHandlerDecorator.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,8 +78,8 @@ public void afterConnectionClosed(WebSocketSession session, CloseStatus closeSta
7878
getDelegate().afterConnectionClosed(session, closeStatus);
7979
}
8080
catch (Throwable ex) {
81-
if (logger.isErrorEnabled()) {
82-
logger.error("Unhandled error for " + this, ex);
81+
if (logger.isWarnEnabled()) {
82+
logger.warn("Unhandled exception after connection closed for " + this, ex);
8383
}
8484
}
8585
}

spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,6 +59,7 @@
5959
* sub-protocol handler to send messages from the application back to the client.
6060
*
6161
* @author Rossen Stoyanchev
62+
* @author Juergen Hoeller
6263
* @author Andy Wilkinson
6364
* @author Artem Bilan
6465
* @since 4.0
@@ -150,8 +151,8 @@ public void addProtocolHandler(SubProtocolHandler handler) {
150151
for (String protocol : protocols) {
151152
SubProtocolHandler replaced = this.protocolHandlerLookup.put(protocol, handler);
152153
if (replaced != null && replaced != handler) {
153-
throw new IllegalStateException("Can't map " + handler +
154-
" to protocol '" + protocol + "'. Already mapped to " + replaced + ".");
154+
throw new IllegalStateException("Cannot map " + handler +
155+
" to protocol '" + protocol + "': already mapped to " + replaced + ".");
155156
}
156157
}
157158
this.protocolHandlers.add(handler);
@@ -257,8 +258,8 @@ public final void stop() {
257258
holder.getSession().close(CloseStatus.GOING_AWAY);
258259
}
259260
catch (Throwable ex) {
260-
if (logger.isErrorEnabled()) {
261-
logger.error("Failed to close '" + holder.getSession() + "': " + ex);
261+
if (logger.isWarnEnabled()) {
262+
logger.warn("Failed to close '" + holder.getSession() + "': " + ex);
262263
}
263264
}
264265
}
@@ -318,7 +319,7 @@ public void handleMessage(Message<?> message) throws MessagingException {
318319
String sessionId = resolveSessionId(message);
319320
if (sessionId == null) {
320321
if (logger.isErrorEnabled()) {
321-
logger.error("Couldn't find session id in " + message);
322+
logger.error("Could not find session id in " + message);
322323
}
323324
return;
324325
}
@@ -397,8 +398,8 @@ protected final SubProtocolHandler findProtocolHandler(WebSocketSession session)
397398
}
398399
catch (Exception ex) {
399400
// Shouldn't happen
400-
logger.error("Failed to obtain session.getAcceptedProtocol(). " +
401-
"Will use the default protocol handler (if configured).", ex);
401+
logger.error("Failed to obtain session.getAcceptedProtocol(): " +
402+
"will use the default protocol handler (if configured).", ex);
402403
}
403404

404405
SubProtocolHandler handler;
@@ -465,17 +466,17 @@ private void checkSessions() {
465466
continue;
466467
}
467468
WebSocketSession session = holder.getSession();
468-
if (logger.isErrorEnabled()) {
469-
logger.error("No messages received after " + timeSinceCreated + " ms. " +
469+
if (logger.isInfoEnabled()) {
470+
logger.info("No messages received after " + timeSinceCreated + " ms. " +
470471
"Closing " + holder.getSession() + ".");
471472
}
472473
try {
473474
this.stats.incrementNoMessagesReceivedCount();
474475
session.close(CloseStatus.SESSION_NOT_RELIABLE);
475476
}
476477
catch (Throwable ex) {
477-
if (logger.isErrorEnabled()) {
478-
logger.error("Failure while closing " + session, ex);
478+
if (logger.isWarnEnabled()) {
479+
logger.warn("Failed to close unreliable " + session, ex);
479480
}
480481
}
481482
}

0 commit comments

Comments
 (0)