Skip to content
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

Merged
merged 5 commits into from
Sep 4, 2024
Merged

Cleanup model proxy #1345

merged 5 commits into from
Sep 4, 2024

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Sep 4, 2024

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

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

Test instructions

Ran the relevant tests with -race and/or -count=1000. E.g.

go test -race -timeout 30s github.com/canonical/jimm/v3/internal/rpc -count=10
go test -timeout 30s -run ^TestProxySockets$ github.com/canonical/jimm/v3/internal/rpc -count=1000

Notes for code reviewers

I suggest reviewing this PR by each commit individually to see the changes more clearly.

@kian99 kian99 requested a review from a team as a code owner September 4, 2024 06:45
- 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.
@kian99 kian99 force-pushed the cleanup-model-proxy branch from 914ef05 to 9983dee Compare September 4, 2024 06:47
Copy link
Contributor

@ale8k ale8k left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

internal/rpc/proxy.go Show resolved Hide resolved
Copy link
Contributor

@SimoneDutto SimoneDutto left a 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

@kian99 kian99 merged commit c300fef into canonical:v3 Sep 4, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants