Handle empty list case in mirrored_supervisor:child/2 (backport #15229)#15231
Merged
michaelklishin merged 1 commit intov4.2.xfrom Jan 9, 2026
Merged
Handle empty list case in mirrored_supervisor:child/2 (backport #15229)#15231michaelklishin merged 1 commit intov4.2.xfrom
mirrored_supervisor:child/2 (backport #15229)#15231michaelklishin merged 1 commit intov4.2.xfrom
Conversation
During production testing of `amazon-mq/rabbitmq-queue-migration`, a
badmatch exception was observed during shovel cleanup:
```
exit:{{{badmatch,[]},[{mirrored_supervisor,child,2,...}]},
{gen_server2,call,[<0.1346.0>,{delete_child,...},infinity]}}
```
The exception occurs in `mirrored_supervisor:child/2` when the list
comprehension returns an empty list instead of a single-element list.
The function uses pattern matching `[Pid] = [...]` which fails when no
matching child is found in the supervisor's children list.
This change updates `child/2` to use a case statement that returns
`undefined` when the list is empty, matching the behavior expected by
`check_stop/3` which already handles `undefined` as "child not found".
The empty list case is safe to treat as `undefined` because it indicates
the child has already been removed from the supervisor, which is the
desired end state for deletion operations.
While we could not reliably reproduce the race condition in testing, the
fix is defensive and aligns with how `terminate_child` can return
`{error, not_found}` when a child doesn't exist. This change makes
`delete_child` operations more robust when children are removed through
other means (supervisor EXIT handling, distributed coordination, etc).
(cherry picked from commit e2c6e8f)
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.
During production testing of
amazon-mq/rabbitmq-queue-migration, a badmatch exception was observed during shovel cleanup:The exception occurs in
mirrored_supervisor:child/2when the list comprehension returns an empty list instead of a single-element list. The function uses pattern matching[Pid] = [...]which fails when no matching child is found in the supervisor's children list.This change updates
child/2to use a case statement that returnsundefinedwhen the list is empty, matching the behavior expected bycheck_stop/3which already handlesundefinedas "child not found". The empty list case is safe to treat asundefinedbecause it indicates the child has already been removed from the supervisor, which is the desired end state for deletion operations.While we could not reliably reproduce the race condition in testing, the fix is defensive and aligns with how
terminate_childcan return{error, not_found}when a child doesn't exist. This change makesdelete_childoperations more robust.This is an automatic backport of pull request #15229 done by [Mergify](https://mergify.com).