Bug: FilteredAsyncMessageHandler does not reset FilterIterator index on return to pool
Description
FilteredAsyncMessageHandler.FilterIterator.Return() does not reset index to 0 before returning the iterator to the pool. As a result, when the iterator is reused from the pool, the filter chain is skipped entirely from the second invocation onward.
The synchronous counterpart FilteredMessageHandler.FilterIterator.Return() correctly resets index = 0, so this appears to be an oversight in the async version.
Steps to Reproduce
- Subscribe to a message with one or more filters using
SubscribeAwait
- Publish the same message multiple times
- Observe that filters are only invoked on the first publish
Expected Behavior
Filters are invoked on every message publish.
Actual Behavior
Filters are only invoked on the first publish. From the second publish onward, filters are skipped and the handler is called directly.
Root Cause
In FilteredAsyncMessageHandler.FilterIterator.Return(), index is not reset:
// FilteredAsyncMessageHandler (bug)
public static void Return(FilterIterator iterator)
{
iterator.handler = null;
iterator.filters = null;
// iterator.index = 0; is missing!
pool.Push(iterator);
}
Compare with the synchronous version which correctly resets index:
// FilteredMessageHandler (correct)
public static void Return(FilterIterator iterator)
{
iterator.handler = null;
iterator.filters = null;
iterator.index = 0; // ✅ present
pool.Push(iterator);
}
Fix
Add iterator.index = 0; to FilteredAsyncMessageHandler.FilterIterator.Return():
public static void Return(FilterIterator iterator)
{
iterator.handler = null;
iterator.filters = null;
iterator.index = 0; // add this
pool.Push(iterator);
}
Environment
- Unity 2022.3.35f1
- ZeroMessenger (latest)
- UniTask
Bug: FilteredAsyncMessageHandler does not reset FilterIterator index on return to pool
Description
FilteredAsyncMessageHandler.FilterIterator.Return()does not resetindexto0before returning the iterator to the pool. As a result, when the iterator is reused from the pool, the filter chain is skipped entirely from the second invocation onward.The synchronous counterpart
FilteredMessageHandler.FilterIterator.Return()correctly resetsindex = 0, so this appears to be an oversight in the async version.Steps to Reproduce
SubscribeAwaitExpected Behavior
Filters are invoked on every message publish.
Actual Behavior
Filters are only invoked on the first publish. From the second publish onward, filters are skipped and the handler is called directly.
Root Cause
In
FilteredAsyncMessageHandler.FilterIterator.Return(),indexis not reset:Compare with the synchronous version which correctly resets
index:Fix
Add
iterator.index = 0;toFilteredAsyncMessageHandler.FilterIterator.Return():Environment