-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: receiving fragmented message gets stuck SOFIE-2680 #188
Conversation
… a response fails, produce an error response, instead of a connection error
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #188 +/- ##
===========================================
+ Coverage 67.81% 79.60% +11.78%
===========================================
Files 5 6 +1
Lines 435 554 +119
Branches 82 101 +19
===========================================
+ Hits 295 441 +146
+ Misses 129 109 -20
+ Partials 11 4 -7
☔ View full report in Codecov by Sentry. |
If there is any data there, it will be incomplete, with the remainder lost due to the broken connection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good improvement fixing some naive assumptions from my side. Couple of notes:
- I'm not a fan of the pattern with setTimeout. I'd rather duplicate line 200 containing the splice than adding many levels of indentation. There is something to say for parsing the responses asynchronously though but then maybe it should be separated into an async private function.
- I'm not a fan of overwriting the response code in case of a parsing error. I would like for this library to be as transparent as possible. I think returning a different data type containing an error would be more suitable. Preferably something that can easily be checked for by a library user. Maybe one could even argue that invalid data is the same as no data?
- Perhaps the unit tests can be simplified a bit by passing around callbacks with the test logic to a function that sets up and tears down the connection.
Yeah, the setImmediate wasn't necessary for the behaviour I was after because of the Promise wrapping, so that has been dropped with that promise pulled out into its own function.
Good point. I've reworked it so that instead of a mangled response, the
I've done a little bit of refactoring, I am not sure what further to do currently |
unit tests for a couple of bugs
The receiving logic is not very durable, and can be broken in a couple of ways:
INFO 1
on a channel with many active layersThis fixes the known failures around fragmented or invalid responses.
There is a behavioural change here, previously an invalid response would result in a connection error and the command timing out. Now, an invalid response will resolve the command promise with a 500 error.
_unprocessedLines
and_unprocessedData
is discarded upon the connection opening/closing, otherwise an incomplete fragment could cause the first response after reconnecting to get lost.Also, it looks like_unprocessedLines
is not cleared when the connection opens. I suspect this will result in TSR triggering a reconnection due to the timeout/error, but the same broken responses will be left in the queue, causing all future commands to also timeout until the device is restarted. I have not attempted to confirm this suspicionI have tested this change with a script set to fire many commands at caspar, and is ensuring that it gets a successful response back.
Prior to this change running
INFO 2
would often time out, due to the reply being split across tcp packets. It is now successfully getting back201
each time