Use hinshun/cancel for cancellable readers without data being consumed#29
Use hinshun/cancel for cancellable readers without data being consumed#29hinshun wants to merge 1 commit intoNetflix:masterfrom
Conversation
coryb
left a comment
There was a problem hiding this comment.
Nice, assuming the cancel readers works reliably this looks like a good improvement.
|
|
||
| require ( | ||
| github.com/creack/pty v1.1.17 | ||
| github.com/hinshun/cancel v0.0.0-20220210052008-740852a68445 // indirect |
There was a problem hiding this comment.
odd that it says indirect here, it is explicitly used in the proejct...
|
The |
|
Looks like someone else already hoisted the package, so I'll let them maintain it: Need to contrib some PRs there first though. |
fc12620 to
4925730
Compare
|
My patches were upstreamed to: https://github.com/muesli/cancelreader We should probably test this with downstreams before considering merging this. |
| select { | ||
| case <-readCh: | ||
| case <-time.After(*readTimeout): | ||
| c.cancelReader.Cancel() | ||
| } |
There was a problem hiding this comment.
Let's use a timer we can explicitly stop here:
| select { | |
| case <-readCh: | |
| case <-time.After(*readTimeout): | |
| c.cancelReader.Cancel() | |
| } | |
| timer := time.NewTimer(*readTimeout) | |
| select { | |
| case <-readCh: | |
| timer.Stop() | |
| case <-timer.C: | |
| c.cancelReader.Cancel() | |
| } |
Otherwise, the timers created by time.After will stay active after a read finishes. If reads are happening very fast, this can cause a lot of unnecessary timers to accumulate.
| func waitTestEnd(t *testing.T, done <-chan struct{}) { | ||
| select { | ||
| case <-done: | ||
| case <-time.After(100 * time.Millisecond): |
There was a problem hiding this comment.
I think this should be at least a few seconds to avoid flakiness on a heavily loaded system.
|
@hinshun: Might be nice to get this one wrapped up. It seemed like a worthwhile improvement. |
…nsumed Signed-off-by: Edgar Lee <edgarl@netflix.com>
|
LGTM |
Eliminate a lot of code with a proper cancellable reader.