Skip to content

Commit

Permalink
Further refine logging in StompErrorHandler
Browse files Browse the repository at this point in the history
In 5.3.x and forward, completely avoid logging unsent CONNECT messages
that are most likely authentication issues before the session is even
established.

Closes gh-26026
  • Loading branch information
rstoyanchev committed Nov 5, 2020
1 parent 17dd778 commit bcd2b9a
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,15 @@ else if (webSocketMessage instanceof BinaryMessage) {
}

for (Message<byte[]> message : messages) {
try {
StompHeaderAccessor headerAccessor =
MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
Assert.state(headerAccessor != null, "No StompHeaderAccessor");
StompHeaderAccessor headerAccessor =
MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
Assert.state(headerAccessor != null, "No StompHeaderAccessor");

StompCommand command = headerAccessor.getCommand();
boolean isConnect = StompCommand.CONNECT.equals(command) || StompCommand.STOMP.equals(command);

StompCommand command = headerAccessor.getCommand();
boolean isConnect = StompCommand.CONNECT.equals(command) || StompCommand.STOMP.equals(command);
boolean sent = false;
try {

headerAccessor.setSessionId(session.getId());
headerAccessor.setSessionAttributes(session.getAttributes());
Expand Down Expand Up @@ -305,7 +307,7 @@ else if (StompCommand.DISCONNECT.equals(command)) {

try {
SimpAttributesContextHolder.setAttributesFromMessage(message);
boolean sent = outputChannel.send(message);
sent = outputChannel.send(message);

if (sent) {
if (this.eventPublisher != null) {
Expand All @@ -327,13 +329,14 @@ else if (StompCommand.UNSUBSCRIBE.equals(command)) {
}
}
catch (Throwable ex) {
if (logger.isErrorEnabled()) {
String errorText = "Failed to send message to MessageChannel in session " + session.getId();
if (logger.isDebugEnabled()) {
logger.debug(errorText, ex);
}
else {
logger.error(errorText + ":" + ex.getMessage());
if (logger.isDebugEnabled()) {
logger.debug("Failed to send message to MessageChannel in session " + session.getId(), ex);
}
else if (logger.isErrorEnabled()) {
// Skip unsent CONNECT messages (likely auth issues)
if (!isConnect || sent) {
logger.error("Failed to send message to MessageChannel in session " + session.getId() +
":" + ex.getMessage());
}
}
handleError(session, ex, message);
Expand Down

0 comments on commit bcd2b9a

Please sign in to comment.