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

Fix TrampolineScheduler NullPointerException #1736

Merged
merged 2 commits into from
Oct 10, 2014

Conversation

benjchristensen
Copy link
Member

I tried for about 30 minutes to replicate the NPE reported in #1702 but couldn't.
It makes sense reading the code that an unsubscribe could trigger an NPE though so I'm fixing it as per recommendation of @DylanSale even though I can't replicate.
I confirmed that the items are being put in the queue BEFORE the wip variable is incremented, so that concurrency seems okay.

I tried for about 30 minutes to replicate the NPE reported in ReactiveX#1702 but couldn't.
It makes sense reading the code that an unsubscribe could trigger an NPE though so I'm fixing it as per recommendation of @DylanSale even though I can't replicate.
I confirmed that the items are being put in the queue BEFORE the wip variable is incremented, so that concurrency seems okay.
@akarnokd
Copy link
Member

akarnokd commented Oct 9, 2014

I found it always odd to have a threadlocal queue and a per-scheduler wip counter. I can't test this now, but I think the NPE may happen if two tasks are scheduled from different threads on the same worker which makes wip = 2 but the thread that is consuming the tasks only sees its threadlocal queue with 1 item.

@benjchristensen
Copy link
Member Author

It is indeed very odd, an artifact of early RxJava trying to match how Rx.Net did unsubscribes and scheduling. As of 0.17 when lift was added that all went away but TrampolineScheduler has not caught up.

This was an awkward leftover from early version of RxJava (pre v0.17).
@benjchristensen
Copy link
Member Author

Just added another commit that removes the use of ThreadLocal.

benjchristensen added a commit that referenced this pull request Oct 10, 2014
Fix TrampolineScheduler NullPointerException
@benjchristensen benjchristensen merged commit 3e7f71f into ReactiveX:1.x Oct 10, 2014
@benjchristensen benjchristensen deleted the issue-1702 branch October 10, 2014 03:20
@akarnokd
Copy link
Member

Instead of removing it, I would have made wip threadlocal as well. That way, the TrampolineScheduler worked like a current-thread scheduler for everyone and not sharing a queue and hopping threads.

@benjchristensen
Copy link
Member Author

It doesn't need to act like a ThreadLocal. It had a separate queue per Worker just like all Scheduler.Worker impls.

Ben Christensen
310.782.5511
@benjchristensen

On Oct 10, 2014, at 12:44 AM, David Karnok notifications@github.com wrote:

Instead of removing it, I would have made wip threadlocal as well. That way, the TrampolineScheduler worked like a current-thread scheduler for everyone and not sharing a queue and hopping threads.


Reply to this email directly or view it on GitHub.

@akarnokd
Copy link
Member

I thought about it a bit and I was mistaken; the Worker needs to keep the tasks in order so threadlocal wip is not good.

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