Made some modifications which caused WorkflowTaskTimedOut in the MoneyTransfer example. Need some help understanding

Hello,

I was fooling around with the example to understand how things work better. Here’s what I tried:

I created two instances of workers from the WorkerFactory, one for workflow implementation and one for activity implementation. So code looks like this -

...
        WorkerFactory factory = WorkerFactory.newInstance(client);

        Worker workflowWorker = factory.newWorker(Shared.MONEY_TRANSFER_TASK_QUEUE);
        Worker activityWorker = factory.newWorker(Shared.MONEY_TRANSFER_TASK_QUEUE);

        workflowWorker.registerWorkflowImplementationTypes(MoneyTransferWorkflowImpl.class);
        activityWorker.registerActivitiesImplementations(new AccountActivityImpl());

        factory.start();
...

When I run the workflow now, I get an intermittent WorkflowTaskTimedOut and then it schedules the WorkflowTask again and then it goes through (See Screenshots)

And in the worker logs, I can see the following exception

Withdrawing $13.740000 from account 001-001. ReferenceId: 1bfe3288-a5d0-4012-bea5-3984fa607e93
07:57:56.993 [Host Local Workflow Poller: 4] ERROR io.temporal.internal.worker.Poller - Failure in thread Host Local Workflow Poller: 4
java.lang.NullPointerException: null
        at io.temporal.internal.worker.WorkflowWorker.apply(WorkflowWorker.java:272)
        at io.temporal.internal.sync.SyncWorkflowWorker.apply(SyncWorkflowWorker.java:215)
        at io.temporal.internal.sync.SyncWorkflowWorker.apply(SyncWorkflowWorker.java:51)
        at io.temporal.internal.worker.PollWorkflowTaskDispatcher.process(PollWorkflowTaskDispatcher.java:75)
        at io.temporal.internal.worker.PollWorkflowTaskDispatcher.process(PollWorkflowTaskDispatcher.java:40)
        at io.temporal.internal.worker.Poller$PollExecutionTask.run(Poller.java:277)
        at io.temporal.internal.worker.Poller$PollLoopTask.run(Poller.java:242)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

Depositing $13.740000 into account 002-002. ReferenceId: 1bfe3288-a5d0-4012-bea5-3984fa607e93
07:58:07.251 [Host Local Workflow Poller: 3] ERROR io.temporal.internal.worker.Poller - Failure in thread Host Local Workflow Poller: 3
java.lang.NullPointerException: null
        at io.temporal.internal.worker.WorkflowWorker.apply(WorkflowWorker.java:272)
        at io.temporal.internal.sync.SyncWorkflowWorker.apply(SyncWorkflowWorker.java:215)
        at io.temporal.internal.sync.SyncWorkflowWorker.apply(SyncWorkflowWorker.java:51)
        at io.temporal.internal.worker.PollWorkflowTaskDispatcher.process(PollWorkflowTaskDispatcher.java:75)
        at io.temporal.internal.worker.PollWorkflowTaskDispatcher.process(PollWorkflowTaskDispatcher.java:40)
        at io.temporal.internal.worker.Poller$PollExecutionTask.run(Poller.java:277)
        at io.temporal.internal.worker.Poller$PollLoopTask.run(Poller.java:242)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

I would love to understand what’s going on here.

Thanks in advance, and sorry about the trouble. Just trying to play with the knobs.

This NPE looks like a bug which we are going to fix. I think it is caused by a code path that wasn’t really planned for. There is no reason to create multiple workers that poll on the same task queue. Try changing your code to:

        WorkerFactory factory = WorkerFactory.newInstance(client);

        Worker worker = factory.newWorker(Shared.MONEY_TRANSFER_TASK_QUEUE);

        worker.registerWorkflowImplementationTypes(MoneyTransferWorkflowImpl.class);
        worker.registerActivitiesImplementations(new AccountActivityImpl());

        factory.start();