fix: implement graceful download queue clearing and throttle concurrent server probes with a semaphore#339
Merged
SuperCoolPencil merged 6 commits intomainfrom Apr 10, 2026
Merged
Conversation
Binary Size Analysis
|
…ent server probes with a semaphore
…nager probe semaphore concurrency limits
… integrity validation
627a72e to
b8f6c86
Compare
…e manager test error handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Greptile Summary
This PR introduces two related improvements:
WorkerPool.GracefulShutdownnow explicitly discards the in-memory queue and drainstaskChanso that buffered-but-unstarted downloads are not picked up by workers after shutdown is initiated; andLifecycleManagergains aprobeSemchannel semaphore that caps simultaneous server probes toMaxConcurrentProbes(default 3), aborting early when the caller's context is cancelled. A small integrity fix also ensures queued DB entries whose.surgefiles have disappeared are cleaned up on startup.Confidence Score: 5/5
Safe to merge — both features are well-implemented and tested; only P2 style issues remain.
All findings are P2: a missing "Requires restart" note in the in-app UI description and a stale comment in a test. The core semaphore logic, queue-clearing, and channel lifecycle are correct. New tests thoroughly cover the added behavior.
internal/config/settings.go (missing "Requires restart" in ui_desc tag for max_concurrent_probes)
Important Files Changed
GracefulShutdown: clears the in-memory queued map, drainstaskChan, waits for active pauses to complete, then closes channels — correct and well-guarded.probeSemchannel semaphore toLifecycleManager;enqueueResolvedacquires a slot before probing and releases via defer. Semaphore is correctly initialized from settings at construction time.MaxConcurrentProbestoNetworkSettingswith default 3; theui_desctag is missing the "Requires restart" note that SETTINGS.md and the adjacentmax_concurrent_downloadsfield include.max_concurrent_probeswith "Requires restart" correctly in the Connection Settings table.ValidateIntegritynow correctly removes queued entries whose.surgefile is absent, fixing a gap where orphaned DB rows could accumulate for queued-then-cancelled downloads.TestLifecycleManager_ProbeSemaphore_LimitsInflightcorrectly uses a non-niladdFuncthat returns an error, but the comment on line 1052 still incorrectly says "addFunc is nil".GracefulShutdownqueue clearing (ClearsQueuedMap,WorkerSkipsQueuedAfterShutdown) and the soft/hard timeout paths — good coverage of the new behavior.TestLocalDownloadService_Shutdown_PersistsQueuedState— intentional, as the new GracefulShutdown purposely discards the in-memory queue rather than persisting it.Sequence Diagram
sequenceDiagram participant Caller participant LifecycleManager participant probeSem participant ProbeServer participant WorkerPool Caller->>LifecycleManager: Enqueue(ctx, req) LifecycleManager->>probeSem: acquire slot (blocks if cap reached) alt ctx cancelled while waiting probeSem-->>LifecycleManager: ctx.Done() LifecycleManager-->>Caller: error: enqueue aborted else slot acquired probeSem-->>LifecycleManager: slot granted LifecycleManager->>ProbeServer: ProbeServerWithProxy() ProbeServer-->>LifecycleManager: ProbeResult (size, range support) LifecycleManager->>WorkerPool: dispatch(finalPath, finalFilename, probe) WorkerPool-->>LifecycleManager: downloadID LifecycleManager->>probeSem: release slot (defer) LifecycleManager-->>Caller: downloadID end Note over WorkerPool: On GracefulShutdown WorkerPool->>WorkerPool: PauseAll() active downloads WorkerPool->>WorkerPool: clear queued map WorkerPool->>WorkerPool: drain taskChan WorkerPool->>WorkerPool: wg.Wait() for pause completion WorkerPool->>WorkerPool: close(progressDone), close(taskChan)Prompt To Fix All With AI
Reviews (2): Last reviewed commit: "fix: remove wrong test" | Re-trigger Greptile