microsoft / microsoft/durabletask-java

`TaskOrchestrationContext.waitForExternalEvent` Timeout "Removed" After Attempting to Schedule Duplicate Orchestration

オープン
#203 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

P2
主要言語
Java
スター
29
フォーク
18
平均マージ
1日 10時間
マージ済み PR(30日)
2

説明

Summary

An orchestration which specifies a timeout for waiting on an external event will seemingly have that timeout "removed"/ignored after another attempt is made to schedule an orchestration instance with the same ID.

Steps to Reproduce

  1. Copy the example below.
  2. Execute the orchestrator-trigger function via HTTP.
@FunctionName("orchestrator-trigger")
public HttpResponseMessage triggerOrchestrator(
    @HttpTrigger(
        name = "request",
        methods = { HttpMethod.GET },
        authLevel = AuthorizationLevel.FUNCTION,
        route = "orchestrator/trigger"
    )
    HttpRequestMessage<String> request,
    @DurableClientInput(name = "durableContext")
    DurableClientContext durableContext,
    ExecutionContext context
) throws InterruptedException {
    DurableTaskClient client = durableContext.getClient();
    String instanceId = "the-only-instance";

    client.scheduleNewOrchestrationInstance("orchestrator", null, instanceId);
    client.raiseEvent(instanceId, "first", 1);

    // Attempting to schedule another orchestration instance with the same instance ID results
    // in the event timeout within the existing orchestrator instance from triggering.
    try {
        client.scheduleNewOrchestrationInstance("orchestrator", null, instanceId);
    } catch (RuntimeException ignored) { }

    Thread.sleep(10_000);
    client.raiseEvent(instanceId, "second", 2);

    return request.createResponseBuilder(HttpStatus.OK).build();
}

@FunctionName("orchestrator")
public void orchestrator(
    @DurableOrchestrationTrigger(name = "orchestration")
    TaskOrchestrationContext orchestration,
    ExecutionContext context
) {
    Task<Integer> firstTask =
        orchestration.waitForExternalEvent("first", Duration.ofSeconds(1), Integer.class);

    Task<Integer> secondTask =
        orchestration.waitForExternalEvent("second", Duration.ofSeconds(1), Integer.class);

    List<Integer> results = orchestration.allOf(firstTask, secondTask).await();
    int first = results.get(0);
    int second = results.get(1);

    System.out.printf("Triggered! First: %s, Second: %s\n", first, second);
}

Expected Result

The orchestration throws an exception due to the second event not arriving within one second.

Actual Result

After ten seconds, the orchestration prints Triggered! First: 1, Second: 2.

Additional Context

Deleting the entire try/catch block that contains the second scheduleNewOrchestrationInstance call results in the expected outcome - the orchestration throws.

This test case is contrived - my actual use case is:

  • A process operates on the combination of a ZIP file and a CSV file.
  • These two files are provided to the application separately, in any order, but at roughly the same time.
  • Whichever file arrives first needs to start an orchestration instance that will wait for both files.
  • We need to avoid a race condition that would result in two separate orchestration instances being created, each waiting for the opposite file. So we'll create a deterministic instance ID based on other data, have the CSV/ZIP receivers always attempt to schedule an orchestration instance with that ID, and ignore the "already exists" error when it occurs.
  • The CSV/ZIP receivers then simply send their own single event to the orchestration instance.
  • The orchestration instance needs to have a timeout in the situation where the second file never arrives.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Issue の Java 再現から始め、TaskOrchestrationContext.waitForExternalEvent と重複した scheduleNewOrchestrationInstance 呼び出しに焦点を当てます。オーケストレーターのトリガーシナリオを実行し、同じインスタンス ID のスケジュールが再度試行された場合でも、2 回目の外部イベントが 1 秒後にタイムアウトすることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
backend, distributed-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。