-
Notifications
You must be signed in to change notification settings - Fork 75
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
Embed mutex in the server's websocket client #200
Embed mutex in the server's websocket client #200
Conversation
This will prevent concurrent writes both in server implementations that store a reference to the client from the OnConnectedFunc callback. Concurrent writes can either occur when the server library responds to agent messages or when the implementation tries to send messages to the server on different threads.
Codecov ReportPatch coverage is
📢 Thoughts on this report? Let us know!. |
case <-timeout.Done(): | ||
t.Error("Client failed to connect before timeout") | ||
default: | ||
if _, ok := srvConnVal.Load().(types.Connection); ok == true { |
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 get a linter warning that ok
is unused if I just have ok
as the if-statement condition. ok == true
fixes the warning, not sure how else to address this.
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. Thanks for fixing.
Hint: https://pkg.go.dev/golang.org/x/perf/cmd/benchstat is very useful for showing before/after benchmark comparison. Here is what it produces for your benchmark results:
Looks like it is close, but could use a more stable execution environment for benchmarking. :-) |
@evan-bradley opamp-go v0.9.0 released: https://github.com/open-telemetry/opamp-go/releases/tag/v0.9.0 |
**Description:** Add tests that verify the Supervisor's behavior using a real Collector binary against an OpAMP server written with the opamp-go library. This tests a basic set of functionality mostly based on what is currently listed as implemented in the Supervisor's feature table. Right now these tests start the Supervisor using the Go API to avoid process handling, but could be changed to start it through a binary in the future. I've placed these tests in the E2E testing workflow even though they run fairly quickly since they depend on a built Collector binary, may become more expansive in the future, and don't fit in any of the existing jobs in the `build-and-test` workflow. I'm open to placing them in another location if we'd prefer them elsewhere. This also updates opamp-go to v0.9.0 to take advantage of open-telemetry/opamp-go#200. **Link to tracking Issue:** Resolves #24292
The Gorilla websocket package states that only one concurrent write can be made to a connection at a time. The library will try to detect concurrent writes and will panic if it detects that one is happening.
We might see concurrent writes in two places:
OnConnectedFunc
.In my opinion it would make sense to prevent concurrent writes within the library to relieve the application from having to worry about this detail. This does necessitate a mutex per connection, but I don't see any significant performance impact from the mutexes.
Without the mutex in
wsConnection
:With the mutex:
This is a fairly rudimentary solution, but it does solve the issue I was seeing and is straightforward. I'm open to more sophisticated ways of managing the write concurrency if there's a deficiency with this approach.