This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new 96a5a983df Improve error handling 96a5a983df is described below commit 96a5a983df47652a8cd74cd570811c85a6416381 Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Dec 6 15:06:09 2023 +0000 Improve error handling --- webapps/docs/changelog.xml | 8 ++++++++ .../classes/websocket/snake/SnakeAnnotation.java | 23 ++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 17548be679..9be9adafd4 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -136,6 +136,14 @@ </scode> </changelog> </subsection> + <subsection name="Web Applications"> + <changelog> + <fix> + Examples. Improve the error handling so snakes associated with a user + that drops from the network are removed from the game. (markt) + </fix> + </changelog> + </subsection> <subsection name="Other"> <changelog> <fix> diff --git a/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java b/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java index 43d61c6dc5..7f14ab8cca 100644 --- a/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java +++ b/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java @@ -17,7 +17,7 @@ package websocket.snake; import java.awt.Color; -import java.io.EOFException; +import java.io.IOException; import java.util.Iterator; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; @@ -115,19 +115,26 @@ public class SnakeAnnotation { @OnError - public void onError(Throwable t) throws Throwable { - // Most likely cause is a user closing their browser. Check to see if - // the root cause is EOF and if it is ignore it. - // Protect against infinite loops. + public void onError(Throwable t, Session session) throws Throwable { + /* + * Assume all errors are fatal. Close the session and remove the snake from the game. + */ + session.close(); + onClose(); + /* + * Correct action depends on root cause. Protect against infinite loops while looking for root cause. + */ int count = 0; Throwable root = t; while (root.getCause() != null && count < 20) { root = root.getCause(); count ++; } - if (root instanceof EOFException) { - // Assume this is triggered by the user closing their browser and - // ignore it. + if (root instanceof IOException) { + /* + * User going away can present in different ways depending on their platform and exactly what went wrong. + * Assume that any IO issue is some form of the user going away and ignore it. + */ } else { throw t; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org