Skip to content

Bug: FilteredAsyncMessageHandler does not reset FilterIterator index on return to pool #19

@YoruYomix

Description

@YoruYomix

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

  1. Subscribe to a message with one or more filters using SubscribeAwait
  2. Publish the same message multiple times
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions