Skip to content

Commit f7d0ea7

Browse files
committed
refactor: if the conn has a context, use afterfunc for cleanup
1 parent d5579e4 commit f7d0ea7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

bitswap/network/ipfs_impl.go

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ func (s *streamMessageSender) Connect(ctx context.Context) (network.Stream, erro
134134
if err != nil {
135135
return nil, err
136136
}
137+
if withCtx, ok := stream.Conn().(HasContext); ok {
138+
context.AfterFunc(withCtx.Context(), func() {
139+
s.stream.Store(nil)
140+
})
141+
}
137142

138143
s.stream.Store(stream)
139144
return stream, nil

0 commit comments

Comments
 (0)