temporalio / temporalio/sdk-java

Cancel long poll if a Future returned from getResultAsync is not referenced anymore by the user code

Open
#1,212 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
433
Forks
249
Avg merge
5d 6h
Merged PRs (30d)
26

Description

Is your feature request related to a problem? Please describe.

If we hit WorkflowStub#getResultAsync and after that, we either don't wait on the result at all or wait for a bit and discard after, the long poll continues to run.
This creates a need for an unpleasant, unconventional WorkflowStub#getResultAsync(resultType, timeout).
Why do users need to pass a timeout to getResultAsync if they pass it into Future.get(timeout).
Most users just use WorkflowStub#getResultAsync(resultType) not understanding that they create a leak if the workflows don't finish fast.

Describe the solution you'd like
Instead of that, Temporal Java SDK code should maintain a weak or phantom reference on the CompletableFuture that we return to the users and cancel the background long poll when it's discarded by the user code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at WorkflowStub#getResultAsync and trace how its CompletableFuture is connected to the background long poll. Determine how discarded futures can be detected safely and how the poll is cancelled, then verify that an unreferenced future no longer leaves a long poll running while a referenced future still completes normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.