-
Notifications
You must be signed in to change notification settings - Fork 8
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
Cleanup model proxy #1345
Cleanup model proxy #1345
Conversation
- Simplified the model proxy to remove the need for a mutex. - Handle an edge case in the model proxy where if the controller routine returned we don't stop the proxy.
914ef05
to
9983dee
Compare
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.
Looks good, addition of once is nice.
websocket.CloseNoStatusReceived, | ||
websocket.CloseAbnormalClosure) | ||
_, unmarshalError := err.(*json.InvalidUnmarshalError) | ||
return closeError || unmarshalError |
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.
I don't like this logic, don't do this. Just check if we have a close error, if we do return else check a marshal error. The name is also confusing, as this is an unexpected closure versus unmarshalling.
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.
Will fix this in a follow-up.
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.
LGTM, i think i added comments in the other pr and it seems you have already addressed them in this new one
Description
This PR recreates #1336 (that PR was coming from my old fork)
This PR modifies the model proxy to improve the error logging and simplify logic in some edge cases.
The reason for this change was that when running JIMM in a test setup there were constant debug logs about "error reading from client" or "error reading from controller" which were completely expected, every time the client closes the websocket our routines waiting to read from the websocket stop and return. In these cases, there were debug and error level logs which were not necessary because this was the normal mode of operation.
The first commit in this PR simply makes the client/controller proxy return a nil error when they fail to read from their respective websocket connections.
The second commit in this PR was done after taking a look at whether we could simplify the complicated logic when handling
ctx.Done()
involving a mutex. It was thankfully easy to clean this up because we already handle things gracefully when the client connection is closed so we can simply close the client connection to clean things up.Finally, I noticed an edge case that wasn't handled and added a test for it. If the connection to the controller was closed unexpectedly, the model proxy would not handle this gracefully. Now if the controller proxy routine ends early, we handle this by stopping the model proxy.
Engineering checklist
Check only items that apply
Test instructions
Ran the relevant tests with
-race
and/or-count=1000
. E.g.Notes for code reviewers
I suggest reviewing this PR by each commit individually to see the changes more clearly.