-
Notifications
You must be signed in to change notification settings - Fork 166
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
Replace http gem with faraday #488
base: master
Are you sure you want to change the base?
Replace http gem with faraday #488
Conversation
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.
Code looks excellent 👏 👍 Haven't tested this yet.
Now that it uses same library as base Client
, I have a feeling we could share more code,
but not a blocker.
while (line = buffer.slice!(/.+\n/)) | ||
yield(@formatter.call(line.chomp)) | ||
end | ||
next if @finished |
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.
The main purpose of finish
method was to allow interrupting a watch from another thread.
The previous implementation by @http_client&.close
was kinda violent but worked — closing the client would cause the code in each
to crash in various ways, depending on where exactly it was when it gets closed, and rescue StandardError
would swallow the crash (when caused by finish
).
A synchronous next if @finished
here is much simpler & safer, but I think it'll only stop the loop after it had something to read, which can take unbounded time (until server sends next update)?
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.
Hm yes that's a very good observation. I'll try to confirm this with a test and then fix it, hopefully having come up with a solution. ;)
This test currently fails because `watcher.finish` does not do its job correctly.
Unfortunately this doesn't work as expected.
@cben I have added the test that tries to close the watch connection from another thread when there are no updates from the API server and, just as you described, the I then added a call to I'm not sure what we can do with this to be honest. Is there a different way to forcibly close the connection? I couldn't find one. Can we get rid of the |
Thanks for looking into this. Neat test! Hmm, I'd like to play with this too. I think this is not an immediate deal-breaker. We can in principle release a breaking 5.0 without Can you mark the test pending/skipped and document that |
Faraday documents
And as far as I can tell, neither Faraday::Adapter::NetHttpPersistent nor Faraday::Adapter::NetHttp implement Is there some way to reach in and actually close the connection? Or close underlying OS socket? ("if violence doesn't help, you're not using enough of it")
BTW, is the test failure with persistent adapter or NetHttp? |
Yes, exactly!
Couldn't find a way, but not an expert in either Ruby or OS/network programming. I wonder if @grosser could help here?
I only tested this with |
That's definitely an interesting notion, I'm not sure how much this would involve but I'll try to investigate this.
Yes, it is a possibility, but certainly not the most pretty... |
Best open an issue in faraday for the close, might be an easy fix.
I touched a bit of code in there, but these edge-cases are always tricky :(
…On Tue, Jan 19, 2021 at 6:21 AM Andrzej Stencel ***@***.***> wrote:
We don't really need finish to close it immediately, just "soon" (this
was already the semantics but should document it).
Perhaps a non-blocking read with a timeout might help?
That's definitely an interesting notion, I'm not sure how much this would
involve but I'll try to investigate this.
I think this is not an immediate deal-breaker. We can in principle release
a breaking 5.0 without finish and hopefully restore it in 5.1...
Yes, it is a possibility, but certainly not the most pretty...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#488 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACYZ4OF5OGFAYSSX75EA3S2WINJANCNFSM4VTATX2A>
.
|
this can be closed, master uses faraday already ? |
No, master uses faraday where we previously used |
Turns out UPDATE: 3/10 as of Jan 2022, Typhoeus too.
|
What prevents kubeclient to use the specific adapter for its own use? Even if the user's app uses faraday with different adapter, it does not have to interfere with what kubeclient uses. The adapter can be configured everytime we create the faraday instance with We already use different client if we don't use faraday in the watch code anyway, so the argument that it would not be aligned with the user's code is IMHO gone. Whatever kubeclient uses is just internal to kubeclient. I guess the only slight disadvantage is that if user uses adapter A, adding kubeclient would add adapter B to their gems? Which already happens with |
Nothing prevents, your analysis is right. |
This pull request replaces the
http
gem with Faraday, in line with a previous PR that replacedrest-client
with Faraday. After this, the only HTTP library used by Kubeclient will be Faraday. This should satisfy #237.Please let me know what you think, I'm happy to take any advice that will help me push this to completion.