-
Notifications
You must be signed in to change notification settings - Fork 556
Improve closing behavior for cache/informer. #505
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import byline = require('byline'); | ||
import request = require('request'); | ||
import { Duplex } from 'stream'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed to move |
||
import { KubeConfig } from './config'; | ||
|
||
export interface WatchUpdate { | ||
type: string; | ||
object: object; | ||
} | ||
|
||
export interface RequestResult { | ||
pipe(stream: Duplex); | ||
destroy(); | ||
} | ||
|
||
export interface RequestInterface { | ||
webRequest(opts: request.Options, callback: (err, response, body) => void): any; | ||
webRequest(opts: request.Options, callback: (err, response, body) => void): RequestResult; | ||
} | ||
|
||
export class DefaultRequest implements RequestInterface { | ||
public webRequest(opts: request.Options, callback: (err, response, body) => void): any { | ||
public webRequest(opts: request.Options, callback: (err, response, body) => void): RequestResult { | ||
return request(opts, callback); | ||
} | ||
} | ||
|
@@ -53,6 +59,7 @@ export class Watch { | |
uri: url, | ||
useQuerystring: true, | ||
json: true, | ||
pool: false, | ||
}; | ||
await this.config.applyToRequest(requestOptions); | ||
|
||
|
@@ -70,6 +77,10 @@ export class Watch { | |
errOut = err; | ||
done(err); | ||
}); | ||
// TODO: I don't love this, because both 'error' and 'close' call the done handler with the same error | ||
// We should probably only do one or the other, but there's challenges because of async delivery and it's | ||
// important to know if the close event is occurring because of an error. So for now, this needs to be | ||
// handled in the client. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of leaving the code in watcher as it is and having workarounds for all potential users of the watcher that are IMHO unreliable anyway, I think it would have been better to fix it here. Would a boolean variable indicating that the done callback was called be sufficient? That way we could guarantee that the done callback is called at most once, that is exactly what users of the watcher expect. |
||
stream.on('close', () => done(errOut)); | ||
|
||
const req = this.requestImpl.webRequest(requestOptions, (error, response, body) => { | ||
|
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 don't see that we would set
this.stopped
to false again in the start() method. If I understand correctly it prevents the cache from being reused. And if we setstopped
tofalse
instart()
method then it would create a race condition whendoneHandler
is called twice andstopped
is set to false between those two calls. To me, that does not look like a good way to go. Fixing the watcher to call doneCallback just once sounds like a better option.