-
Notifications
You must be signed in to change notification settings - Fork 70
Use hinshun/cancel for cancellable readers without data being consumed #29
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
base: master
Are you sure you want to change the base?
Conversation
coryb
left a comment
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.
Nice, assuming the cancel readers works reliably this looks like a good improvement.
go.mod
Outdated
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
expect_test.go
Outdated
| func waitTestEnd(t *testing.T, done <-chan struct{}) { | ||
| select { | ||
| case <-done: | ||
| case <-time.After(100 * time.Millisecond): |
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 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 <[email protected]>
|
LGTM |
Eliminate a lot of code with a proper cancellable reader.