Repository navigation
Conversation
Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com>
Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com>
|
@dicej When you get a chance, I'd appreciate another pair of eyes on this. If you'd like to try this out locally, I've drafted a PR with my changes to wit-bindgen: bytecodealliance/wit-bindgen#1779 |
dicej
left a comment
There was a problem hiding this comment.
Thanks for doing this!
Once again, I've hit the limits of my Go experience and don't know how surprising it would be to an application programmer for runtime.Goexit() to be called when e.g. calling an async import or reading/writing a stream/future.
My guess is that idiomatic support for cancellation will involve context's cancellation features, which will in turn require deeper bindings changes. What you have here seems like a reasonable first step, though.
cc @jfleitz or @dgryski, who both have way more Go experience than I do.
| case EVENT_TASK_CANCELLED: | ||
| state.cancelled = true | ||
| for waitable, channel := range state.pending { | ||
| delete(state.pending, waitable) |
There was a problem hiding this comment.
Nit, rather than delete the entries one-by-one, you could do (EDIT per Damian's comment below: state.pending = state.pending[:0]clear(state.pending)) after the loop, which is likely more efficient.
There was a problem hiding this comment.
pending is a map; setting the length to 0 ([:0]) is only valid for slices. The efficient way to clear it is clear(state.pending) (which also works for slices, btw.). Note that if pending were a slice, pending[:0] sets the length to 0, but the entries are still referenced by the backing array and won't be garbage collected. This probably doesn't apply in this case, but good to know anyway.
|
Yes, wiring in |
|
@asteurer per Damian's confirmation that What do you think? |
|
BTW, using |
Fixes #17.
Summary
The issue above identified a bug where a panic occurs when a future is cancelled and then written to, when it should be an error. While working on this, I also identified issues with streams permanently blocking after cancellation and added a fix for that as well.
Call outs
There were a couple of ways that we could have handled cancellation. One was to change the futures/streams API to return errors that would report whether a task was cancelled, but decided against this because it would introduce a breaking change and be more tedious for developers to use. I instead chose to use
runtime.Goexit()because it seems to offer the simplest solution; however, I'm open to discussing this further.