fix: resolve variable shadowing causing allServices count to always report 0 in swarm mode#736
Merged
m90 merged 1 commit intooffen:mainfrom Feb 26, 2026
Conversation
…e 0 in swarm mode
Member
|
🎣 good catch, not sure how that regression slipped through. Thanks for fixing. Also +1 on being transparent on how this was created, I don't mind at all as long as it's known to all parties 👍 |
Member
|
This is now released in v2.47.2 |
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.
Fix variable shadowing bug causing incorrect service count in log message
This is my first ever pull request - this is all new to me so I hope everything is in order!
I am no Go expert and used an LLM to help find the bug so I am not sure this is the preffered way to resolve.
I rebuilt the Docker image locally, pushed it to my local container registry, and tested it against my Swarm stack. Complete logs are included below to show that logging now correctly shows the number of active services.
Problem
In
stopContainersAndServices()within the swarm handling block, theallServicesvariable declared in the outer scope is shadowed by a new inner-scope variable due to the use of:=instead of=:This means the outer
allServicesis never populated, so when it is referenced in the log message:The count always reports
0, producing misleading log output such as:Note:
s.stats.Services.Allis also affected and will always be0.Fix
Change
:=to=when assigningresult.ItemstoallServices:Real-world reproduction
Before fix — service count incorrectly reports
0:After fix — service count correctly reports all 21 services in the swarm:
Full log output
Before:
After: