papegaaij commented on code in PR #1900:
URL: https://github.com/apache/wicket/pull/1900#discussion_r4591818164


##########
wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java:
##########
@@ -344,7 +362,13 @@ public final void broadcastMessage(final IWebSocketMessage 
message, IWebSocketCo
                                }
                                else
                                {
-                                       LOG.debug("Page with id '{}' has been 
expired. No message will be broadcast!", pageId);
+                                       
connectionRegistry.removeConnection(application, sessionId, 
connection.getKey());
+                                       LOG.debug("Page with id '{}' has 
expired. Closing the connection with key '{}'.",

Review Comment:
   This logs "Closing the connection" even for the special messages, where the 
connection is only removed from the registry. Someone tracking down a lingering 
connection would be misled by it. Maybe log only when it actually closes, or 
word it so it covers both cases.



##########
wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java:
##########
@@ -344,7 +362,13 @@ public final void broadcastMessage(final IWebSocketMessage 
message, IWebSocketCo
                                }
                                else
                                {
-                                       LOG.debug("Page with id '{}' has been 
expired. No message will be broadcast!", pageId);
+                                       
connectionRegistry.removeConnection(application, sessionId, 
connection.getKey());
+                                       LOG.debug("Page with id '{}' has 
expired. Closing the connection with key '{}'.",
+                                               pageId, connection.getKey());
+                                       if (isSpecialMessage(message) == false)

Review Comment:
   Skipping the close is right for a `ClosedMessage`, but an `ErrorMessage` 
doesn't mean the transport is going away. If the socket survives the error, 
this removes the connection from the registry and leaves it open. Every later 
frame from the client then finds no connection, is dropped with a debug log, 
and the client never gets the "Page expired" close. That's the half-dead 
connection this PR is meant to remove. `AbortedMessage` doesn't need the 
exemption either, since `onConnect` closes the connection itself right after 
broadcasting it. `close()` is already a no-op on a closed connection, so only a 
`ClosedMessage` needs exempting.
   
   The session-ended branch above (326–335) has the same guard, and the 
refused-resource branch (337–344) repeats the same remove/log/close steps. 
Could the three go into one private helper, something like 
`closeConnection(connection, message, reason)`? Then the order of remove and 
close and the exemption for closing messages live in one place, and this fix 
applies to all three.
   
   On the test side: the registry assertion in 
`aClosingConnectionToAnExpiredPageIsNotClosedAgain` (test line 258) passes even 
without the new `removeConnection`, because `onClose` always removes the 
connection after broadcasting. The `ErrorMessage` path isn't covered at all. 
`WebSocketTester` has no way to raise `onError` yet, so it would need a small 
addition to test that path.



##########
wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java:
##########
@@ -344,7 +362,13 @@ public final void broadcastMessage(final IWebSocketMessage 
message, IWebSocketCo
                                }
                                else
                                {
-                                       LOG.debug("Page with id '{}' has been 
expired. No message will be broadcast!", pageId);
+                                       
connectionRegistry.removeConnection(application, sessionId, 
connection.getKey());
+                                       LOG.debug("Page with id '{}' has 
expired. Closing the connection with key '{}'.",
+                                               pageId, connection.getKey());
+                                       if (isSpecialMessage(message) == false)
+                                       {
+                                               
connection.close(WebSocketConnectionOriginFilter.POLICY_VIOLATION_ERROR_CODE, 
PAGE_EXPIRED);
+                                       }
                                }
                        }
                        catch (Exception x)

Review Comment:
   Only a `null` from `getPage` is treated as an expired page. If the page 
store throws while loading the page instead, this catch logs it and leaves the 
connection open and registered. That happens, for example, when a stored page 
no longer deserializes after a redeploy, which is close to the restart case 
from the issue. The client stays on the same silent socket, and every frame or 
push logs an ERROR. Could an unrecoverable page-load failure take the same 
remove-and-close path?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to