diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-30 23:58:30 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-30 23:58:30 +0300 |
| commit | a3f6bb625aad2cd4a0c86af44feaa22aa401331f (patch) | |
| tree | 79878744944bebf5a4346ca0bff338be83a20f23 /internal/server/handlers/serverhandler.go | |
| parent | 7a917e6e81bf8e956eff2a4a54e9300ab2747949 (diff) | |
feat: track pending files to prevent premature server shutdown
- Add pendingFiles counter to ServerHandler to track files waiting for limiter slots
- Only shutdown when both activeCommands and pendingFiles are zero
- Increment pendingFiles when starting to process a batch of files
- Decrement as each file completes processing
- Add comprehensive logging for debugging shutdown issues
- Flush turbo data before signaling EOF to ensure all data is transmitted
This fixes the issue where the server would shutdown while files were still
queued in the catLimiter, causing incomplete processing when MaxConcurrentCats
is lower than the number of files being processed.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/server/handlers/serverhandler.go')
| -rw-r--r-- | internal/server/handlers/serverhandler.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/internal/server/handlers/serverhandler.go b/internal/server/handlers/serverhandler.go index 69bebc4..9163447 100644 --- a/internal/server/handlers/serverhandler.go +++ b/internal/server/handlers/serverhandler.go @@ -3,6 +3,7 @@ package handlers import ( "context" "strings" + "sync/atomic" "github.com/mimecast/dtail/internal" "github.com/mimecast/dtail/internal/config" @@ -21,6 +22,8 @@ type ServerHandler struct { catLimiter chan struct{} tailLimiter chan struct{} regex string + // Track pending files waiting for limiter slots + pendingFiles int32 } // NewServerHandler returns the server handler. @@ -60,7 +63,12 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, ltx lcontext.LCon dlog.Server.Debug(h.user, "Handling user command", argc, args) h.incrementActiveCommands() commandFinished := func() { - if h.decrementActiveCommands() == 0 { + activeCommands := h.decrementActiveCommands() + pendingFiles := atomic.LoadInt32(&h.pendingFiles) + dlog.Server.Debug(h.user, "Command finished", "activeCommands", activeCommands, "pendingFiles", pendingFiles) + + // Only shutdown if no active commands AND no pending files + if activeCommands == 0 && pendingFiles == 0 { h.shutdown() } } |
