Skip to content

Commit a504b5f

Browse files
committed
fix: context cancellation
1 parent be9f2ac commit a504b5f

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

pkg/api/gsoc.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,23 @@ func (s *Service) gsocListeningWs(conn *websocket.Conn, socAddress swarm.Address
171171
defer s.wsWg.Done()
172172

173173
var (
174-
dataC = make(chan []byte, 2) // small buffer to decouple producer/consumer
175-
gone = make(chan struct{})
176-
slow = make(chan struct{})
177-
slowOnce sync.Once
178-
ticker = time.NewTicker(s.WsPingPeriod)
179-
ctx, cancel = context.WithCancel(context.Background()) // for storing cached chunks
180-
err error
174+
dataC = make(chan []byte, 2) // small buffer to decouple producer/consumer
175+
gone = make(chan struct{})
176+
slow = make(chan struct{})
177+
slowOnce sync.Once
178+
ticker = time.NewTicker(s.WsPingPeriod)
179+
err error
181180
)
182181
defer func() {
183-
cancel()
184182
ticker.Stop()
185183
_ = conn.Close()
186184
}()
187185
cleanup := s.gsoc.Subscribe(socAddress, func(c *soc.SOC) {
188186
if cacheWrappedChunk {
189-
if err := s.storer.Cache().Put(ctx, c.WrappedChunk()); err != nil {
187+
// Caching is a node-local side effect independent of this
188+
// subscriber's connection, so it must not be aborted just
189+
// because the websocket closes mid-write.
190+
if err := s.storer.Cache().Put(context.Background(), c.WrappedChunk()); err != nil {
190191
s.logger.Debug("gsoc ws: cache wrapped chunk failed", "error", err)
191192
}
192193
}

0 commit comments

Comments
 (0)