Fix infinite loop when SocketServerCollector receives invalid packet#23
Open
mroch wants to merge 1 commit intomatthewwall:masterfrom
Open
Fix infinite loop when SocketServerCollector receives invalid packet#23mroch wants to merge 1 commit intomatthewwall:masterfrom
mroch wants to merge 1 commit intomatthewwall:masterfrom
Conversation
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.
When in
--ip-mode=server, if a rogue client connects, it causes the server to go into an infinite loop trying to "retry" reading in_blockingread:mtools/bin/btmon.py
Lines 2324 to 2347 in fa488f9
READ_RETRIES == 0. for each invalid character,_readraisesReadError, so it keeps reading until it hits EOF. then it raises anEmptyReadErrorand waitsRETRY_WAIT(60 seconds), then tries to_readfrom the still-closed socket. This errors, ad nauseum.This behavior makes sense for serial, since the only way to synchronize is to consume until you hit the packet header. But IP packets will never recover, so we don't need the
_blockingreadbehavior and can just call_read.There was one further issue: if the client disconnects quickly, then
self._conn.shutdown()throws because the socket is already closed.shutdownis unnecessary in this case so we just ignore exceptions.Test:
run
bin/btmon.py --packet-format=gem48ptbin --ip --ip-mode=server --ip-port=5000 --debug --printrun
telnet localhost 5000, send something like HELLO, ^], ctrl-d to disconnectrun telnet again, immediately ^], ctrl-d without sending anything
Fixes #22