Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerable overload of Zip does not synchronize enumerator disposal #132

Closed
glopesdev opened this issue Sep 12, 2015 · 1 comment · Fixed by #1079
Closed

Enumerable overload of Zip does not synchronize enumerator disposal #132

glopesdev opened this issue Sep 12, 2015 · 1 comment · Fixed by #1079
Assignees

Comments

@glopesdev
Copy link

Iterators are synchronized structures that do not expect to be called reentrantly.

The current implementation of Zip that takes in an IEnumerable source calls the Dispose method of the iterator directly when the subscription is disposed. However, this raises the possibility that active MoveNext calls are still being executed asynchronously on another thread.

The example below illustrates this scenario.

static IEnumerable<int> MyEnum()
{
    try
    {
        Console.WriteLine("start");
        Thread.Sleep(2000);
        Console.WriteLine("yield");
        yield return 0;
    }
    finally
    {
        Console.WriteLine("dispose");
    }
}

static void Main(string[] args)
{
    var timer = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1));
    var handle = timer.Zip(MyEnum(), (x, y) => y).Subscribe();
    Thread.Sleep(500);
    handle.Dispose();
    Console.ReadLine();
}
@akarnokd
Copy link
Collaborator

Sounds like a forgotten bug. I'll look into it for 4.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants