@cryptotaxi247 / kubo / commits / 4ef780a9c

fix(bitswap) signal termination to async'ly spawned workers

License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Nov 20, 2014 at 18:28 UTC 4ef780a9c96547fa10423cef8c7f4c7630cf3852
1 file changed +5 -2
exchange/bitswap/bitswap.go
+5 -2
@@ -163,7 +163,10 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
163 }
164
165 // TODO ensure only one active request per key
166 -func (bs *bitswap) loop(ctx context.Context) {
166 +func (bs *bitswap) loop(parent context.Context) {
167 +
168 + ctx, cancel := context.WithCancel(parent)
169 + defer cancel() // signal termination
170
171 // Every so often, we should resend out our current want list
172 rebroadcastTime := time.Second * 5
@@ -190,7 +193,7 @@ func (bs *bitswap) loop(ctx context.Context) {
193 log.Errorf("error sending wantlist: %s", err)
194 }
195 }
193 - case <-ctx.Done():
196 + case <-parent.Done():
197 return
198 }
199 }