Skip to content

weboperations: make /-/reload handler cancellation-safe #5103

@coderabbitai

Description

@coderabbitai

Summary

The POST /-/reload handler in weboperations/weboperations.go has two potential hang/safety issues:

  1. Unbuffered reply channel can cause a deadlock: If the client disconnects after the reload has been queued, the reloader goroutine will block forever trying to send the result back on the unbuffered errc channel, because no one is receiving.
  2. defer close(errc) is incorrect: The handler is not the sender on this channel — closing it from the handler side is unsafe and could panic the reloader if it tries to send on a closed channel.
  3. Neither the enqueue nor the reply is context-aware: If the reload queue (reloadCh) is full or the reload takes too long, the HTTP handler hangs with no way for a client disconnect to unblock it.

Suggested Fix

  • Change errc to a buffered channel of size 1: errc := make(chan error, 1)
  • Remove defer close(errc)
  • Wrap both the send to reloadCh and the receive from errc in select statements that also listen on req.Context().Done()

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions