-
Notifications
You must be signed in to change notification settings - Fork 6
synchronize context cancellation with writing to the result channel #34
Comments
@ajnavarro: I will take this (I cannot assign myself to the issue). |
@ajnavarro : go ahead and create a PR here to add you to w3dt-stewards team: https://github.com/ipld/github-mgmt . That should give you the ability to self-assign. |
Also, it looks like we'll need to associate this repo with w3dt-stewards team as well. That can be in the same PR. |
@BigLep done here: ipld/github-mgmt#9 |
What if Edelweiss returns iterators for these collections, and only generates a method that returns an iterator, instead of sync+async? It'd remove all this confusing async machinery, spawn one less goroutine for sync calls, and if consumer wants async, they can just wrap it in a goroutine, which is a lot easier IMO since they'd own the entire lifetime of the channel and goroutine, cancellation semantics, etc. The iterator would need to be explicitly closed so that it closes the underlying HTTP response body. |
@guseggert I created an issue with a proposal for using iterators instead of channels here: #38 |
I am reopening this issue, as the PR does not synchronize channel sends with context cancellation. I left a note in the merged PR that explains the problem. |
Generated client method implementations must stop writing to the result channels as soon as they see "context cancelled".
This relieves clients from the responsibility to drain the result channel after they cancel the context.
A few changes in the generated code are required:
When context cancellation is detected, an error message should not be sent to the result channel:
https://github.com/ipld/edelweiss/blob/main/blueprints/services/dagjson-over-http/client.go#L284
All writing to the result channel should be paired with synchronized checks for context cancellation:
https://github.com/ipld/edelweiss/blob/main/blueprints/services/dagjson-over-http/client.go#L293
https://github.com/ipld/edelweiss/blob/main/blueprints/services/dagjson-over-http/client.go#L299
https://github.com/ipld/edelweiss/blob/main/blueprints/services/dagjson-over-http/client.go#L304
https://github.com/ipld/edelweiss/blob/main/blueprints/services/dagjson-over-http/client.go#L310
The text was updated successfully, but these errors were encountered: