Harden process ring buffer and daemon/health shutdown behavior

This commit is contained in:
Virgil 2026-04-03 07:36:44 +00:00
parent 2d68f89197
commit 8b0fe175b9
3 changed files with 16 additions and 3 deletions

View file

@ -19,6 +19,10 @@ type RingBuffer struct {
//
// rb := process.NewRingBuffer(256)
func NewRingBuffer(size int) *RingBuffer {
if size <= 0 {
size = 1
}
return &RingBuffer{
data: make([]byte, size),
size: size,

View file

@ -164,7 +164,9 @@ func (d *Daemon) Stop() error {
// Auto-unregister
if d.opts.Registry != nil {
_ = d.opts.Registry.Unregister(d.opts.RegistryEntry.Code, d.opts.RegistryEntry.Daemon)
if err := d.opts.Registry.Unregister(d.opts.RegistryEntry.Code, d.opts.RegistryEntry.Daemon); err != nil {
errs = append(errs, core.E("daemon.stop", "registry", err))
}
}
d.running = false

View file

@ -104,10 +104,17 @@ func (h *HealthServer) Start() error {
// Stop gracefully shuts down the health server.
func (h *HealthServer) Stop(ctx context.Context) error {
if h.server == nil {
h.mu.Lock()
server := h.server
h.server = nil
h.listener = nil
h.mu.Unlock()
if server == nil {
return nil
}
return h.server.Shutdown(ctx)
return server.Shutdown(ctx)
}
// Addr returns the actual address the server is listening on.