Skip to content

Handle empty list case in mirrored_supervisor:child/2 (backport #15229)#15231

Merged
michaelklishin merged 1 commit intov4.2.xfrom
mergify/bp/v4.2.x/pr-15229
Jan 9, 2026
Merged

Handle empty list case in mirrored_supervisor:child/2 (backport #15229)#15231
michaelklishin merged 1 commit intov4.2.xfrom
mergify/bp/v4.2.x/pr-15229

Conversation

@mergify
Copy link
Copy Markdown

@mergify mergify bot commented Jan 8, 2026

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.


This is an automatic backport of pull request #15229 done by [Mergify](https://mergify.com).

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)
@michaelklishin michaelklishin added this to the 4.2.3 milestone Jan 9, 2026
@michaelklishin michaelklishin merged commit fe8839e into v4.2.x Jan 9, 2026
291 checks passed
@michaelklishin michaelklishin deleted the mergify/bp/v4.2.x/pr-15229 branch January 9, 2026 00:01
michaelklishin added a commit that referenced this pull request Jan 9, 2026
Handle empty list case in `mirrored_supervisor:child/2` (backport #15229) (backport #15231)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants