Skip to content

TrampolineScheduler NullPointerException #1702

Closed

Description

@DylanSale

There is an issue in TrampolineScheduler on 0.20.4 where it can throw a NullPointerException in InnerCurrentThreadScheduler enqueue(Action0 action, long execTime)

        private Subscription enqueue(Action0 action, long execTime) {
            if (innerSubscription.isUnsubscribed()) {
                return Subscriptions.empty();
            }
            PriorityQueue<TimedAction> queue = QUEUE.get();
            final TimedAction timedAction = new TimedAction(action, execTime, COUNTER_UPDATER.incrementAndGet(TrampolineScheduler.this));
            queue.add(timedAction);

            if (wip.getAndIncrement() == 0) {
                do {
                    queue.poll().action.call();
                } while (wip.decrementAndGet() > 0);
                return Subscriptions.empty();
            } else {
                // queue wasn't empty, a parent is already processing so we just add to the end of the queue
                return Subscriptions.create(new Action0() {

                    @Override
                    public void call() {
                        PriorityQueue<TimedAction> _q = QUEUE.get();
                        if (_q != null) {
                            _q.remove(timedAction);
                        }
                    }

                });
            }
        }

The Exception happens on queue.poll().action.call();.
From what I can tell, the queue is empty, and poll is returning null.

This is happening inside a nested observable.redo().timeout().redo() chain (the redo().timeout() happens earlier in the application, it isn't just one after the other like that), if that helps. I'm not in a position to create a simple replication example however.

My current theory is: One of the redos could be unsubscribing, calling _q.remove, while the wip loop is running (perhaps unsubscribe is happening on another thread?), causing the queue to become empty, and the next loop of the wip loop returns null. I think the queue.poll() call should check for null.

Activity

  1. benjchristensen commented on Oct 1, 2014

    @benjchristensen
    Member

    Thanks for the report. I'll take a look.

  2. added this to the 1.0 milestone on Oct 7, 2014
  3. benjchristensen commented on Oct 10, 2014

    @benjchristensen
    Member

    Fixed (I hope) in #1736

  4. added a commit that references this issue on Jan 23, 2015
  5. akarnokd commented on Jan 23, 2015

    @akarnokd
    Member

    Hi. Fixed in 1.x branch via #2471. Can you verify the fix works for your case?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions