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

Add context and lock functionality to client interface #108

Merged
merged 17 commits into from
Jun 27, 2023

Conversation

directionless
Copy link
Member

@directionless directionless commented May 27, 2023

As discussed in #98, the osquery thrift socket is can only handle a single caller.

In #99, I tried adding a mutex. But, with a mutex, it didn't feel like there was a good timeout behavior. Looking round, I considered a rate.Limiter, but I find those very hard to understand. And eventually I found this suggestion for using single sized channels as a form of mutex.

This should allow for exclusive locking, timeouts, and ctx cancelation.

I have also stopped exporting the raw osquery thrift client. Using it would bypass these locks, and feels like an antipattern. However, it does make this a breaking change.

I also bumped the go version because CI was complaining

Fixes: #98
Closes: #99

@directionless directionless requested a review from zwass May 27, 2023 01:55
@directionless
Copy link
Member Author

@aleksmaus @RebeccaMahany I know you've both poked around here. How's this approach feel?

@directionless directionless marked this pull request as ready for review May 27, 2023 02:05
Copy link
Contributor

@James-Pickett James-Pickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

client.go Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very cool way to use channels!

Copy link
Contributor

@RebeccaMahany RebeccaMahany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

client.go Outdated Show resolved Hide resolved
locker.go Show resolved Hide resolved
client_test.go Outdated Show resolved Hide resolved
locker.go Outdated Show resolved Hide resolved
@directionless
Copy link
Member Author

directionless commented Jun 1, 2023

I found a corner that doesn't seem great. I'm downgrading this to draft while I tinker.

Update: Fixed. Calling Unlock when unlocked, now panics. As it does with mutex.

@directionless directionless marked this pull request as draft June 1, 2023 02:05
@directionless directionless marked this pull request as ready for review June 1, 2023 03:13
Copy link

@aleksmaus aleksmaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

client_test.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
locker.go Outdated Show resolved Hide resolved
locker.go Show resolved Hide resolved
directionless and others added 2 commits June 6, 2023 22:00
Co-authored-by: Zach Wasserman <zach@fleetdm.com>
@directionless
Copy link
Member Author

@zwass nudge nudge?

@directionless
Copy link
Member Author

@zwass @lucasmrod I'd love a thumb from y'all. Mostly because I don't want to inadvertently break what you're doing. I think there's enough support for this, so I'm going to end up merging it. But I do want to give y'all time to object / approve / etc

@directionless
Copy link
Member Author

Hearing no objections and tentative approval, I'm going to merge this.

@directionless directionless merged commit 6bcabfb into osquery:master Jun 27, 2023
@directionless directionless deleted the seph/context branch June 27, 2023 15:56
@zwass
Copy link
Member

zwass commented Jun 27, 2023

Yes that makes sense. I don't think this will cause any issues for us. Thanks!

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.

Should we add mutexs to osquery-go?
5 participants