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

Poll shared cache connect #1489

Merged
merged 3 commits into from
Dec 18, 2023
Merged

Poll shared cache connect #1489

merged 3 commits into from
Dec 18, 2023

Conversation

JakeSiFive
Copy link
Contributor

I'll start out by saying, I'm not a fan of this PR but I was just noodling on what we could do to help with this problem if it occurs in the future. Ideally we'd having a polling mechanism here but at this moment I'm not at all sure how to do that. It appears to me that Tokio and mio have solved this problem somehow so I think there's a better solution out there. This change does not eliminate the core issue like the previous PR did and because it at best reduces spurious daemon launches by 2x it doesn't eliminate DoS-ing yourself by spamming wake invocations, it just reduces the impact a little bit...I'm gonna put this up and see what people think but I'm rather on the fence about landing it.

wcl::log::info("key = %s, sizeof(key) = %lu", key, sizeof(key))();
memcpy(addr.sun_path + 1, key, sizeof(key));
if (connect(socket_fd.get(), reinterpret_cast<const sockaddr *>(&addr), sizeof(key)) == -1) {
if (errno == EAGAIN) {
addr_bound = true;
Copy link
Contributor

@V-FEXrt V-FEXrt Dec 11, 2023

Choose a reason for hiding this comment

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

The logic around the bool& here is tricky and hard to follow. You should just change the return type to wcl::result with an error enum of enum { Generic, AddrBound } which will make this function clearer but more importantly will make the callsite several times better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that does seem better. I was thinking of doing something like that but I got lazy lol

@V-FEXrt
Copy link
Contributor

V-FEXrt commented Dec 11, 2023

I don't hate the overall structure and it does seem reasonable to me to limit daemon launches if we already know its launched. My vote would be to land if we can clean up the logic a little bit

@JakeSiFive
Copy link
Contributor Author

I don't hate the overall structure and it does seem reasonable to me to limit daemon launches if we already know its launched. My vote would be to land if we can clean up the logic a little bit

Yeah that makes sense, let me investigate how tokio and mio solve this first before going this route. If we do go this route then using a result to clean up the logic is preferable no doubt.

@JakeSiFive
Copy link
Contributor Author

I was thinking about this and my initial logic on this was wrong. I thought it would flip back and forth between launching and not launching but it actually should re-test for the connection being valid every time so it should keep not re-launching by continuously reconfirming that the other end of the socket is still bound. So this is actually quite a good strategy for reducing log churn, process churn, and should help reduce contention so I'm on board with this. I'll clean this up on Wednesday and we can land it.

@JakeSiFive JakeSiFive merged commit f239125 into master Dec 18, 2023
12 checks passed
@JakeSiFive JakeSiFive deleted the poll_shared_cache_connect branch December 18, 2023 21:57
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.

2 participants