Set a more sane timeout for WS connections and log WS errors#1992
Merged
mcm001 merged 1 commit intoPhotonVision:mainfrom Jul 9, 2025
Merged
Set a more sane timeout for WS connections and log WS errors#1992mcm001 merged 1 commit intoPhotonVision:mainfrom
mcm001 merged 1 commit intoPhotonVision:mainfrom
Conversation
mcm001
approved these changes
Jul 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
As described in #1827 (comment), setting the idle timeout to 5 seconds, as done here, seems to fix the WebSockets connection dying "permanently." Now, Javalin will throw a TimeoutException after a short time, after which the WebSockets connection becomes functional again. The behavior is a little strange though; disconnecting my Ethernet cable, reconnecting it to get the same IP address, then opening the page will sometimes work, and continue to work after refreshing multiple times, until one refresh will show the broken UI briefly, before it starts working again. Or it might be time based and refreshes have nothing to do with it, unsure. Regardless, the logs will record a new WebSocket connection, the TimeoutException getting thrown, then the closing of the WebSockets connection with a UUID. The timeout does seem to help; during one testing session, the placeholder UI showed up after a refresh, stayed visible for multiple seconds, and then everything loaded in; the exception was thrown right around the same time the UI came back up, which gives me confidence that the timeout will allow PV to eventually recover without needing a reboot even in scenarios where the WebSocket connection might be unstable. It does appear that the connection was simply being kept open for too long, causing issues when a new one was made with the same IP address, and simply allowing it to close fixes it. I personally tested quite a few disconnect-reconnect loops, and reproed multiple times on main, and zero times with this branch where the UI didn't recover.
I also want to note that when the connection is severed and left alone, the TimeoutException is not thrown after 5 seconds, but instead seems to take upwards of a minute. I'm unsure as to why, but I assume it's something deeper in the networking stack. I've also seen ClosedChannelException get thrown instead of TimeoutException, which appears to be normal according to Javalin.
I've also added logging for when WebSocket errors are thrown. I believe the exceptions are thrown anyways by DataChangeService, but they seem a bit different, and more details is always better.
Closes #1827, closes #1320, closes #1182.
Meta
Merge checklist: