Fix crash due to incorrect event deletion of evport (#14162)

This PR fixes
https://github.com/redis/redis/issues/14056#issuecomment-3026114590

## Summary
Because evport uses `eventLoop->events[fd].mask` to determine whether to
remove the event, but in ae.c we call `aeApiDelEvent()` before updating
`eventLoop->events[fd].mask`, this causes evport to always see the old
value, and as a result, `port_dissociate()` is never called to remove
the fd.
This issue may not surface easily in a non-multithreaded, but since in
the multi-threaded case we frequently reassign fds to different threads,
it makes the crash much more likely to occur.
This commit is contained in:
debing.sun
2025-07-03 14:41:26 +08:00
committed by YaacovHazan
parent 475da081d7
commit 4df48593ad

View File

@@ -216,7 +216,9 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
* the fact that our caller has already updated the mask in the eventLoop.
*/
fullmask = eventLoop->events[fd].mask;
/* We always remove the specified events from the current mask,
* regardless of whether eventLoop->events[fd].mask has been updated yet. */
fullmask = eventLoop->events[fd].mask & ~mask;
if (fullmask == AE_NONE) {
/*
* We're removing *all* events, so use port_dissociate to remove the