Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ private WorkflowThread newRootThread(Runnable runnable) {
"newRootThread can be called only if there is no existing root workflow thread");
}
rootWorkflowThread =
new WorkflowThreadImpl(
new RootWorkflowThreadImpl(
workflowThreadExecutor,
workflowContext,
this,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
*
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this material except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.temporal.internal.sync;

import io.temporal.common.context.ContextPropagator;
import io.temporal.internal.worker.WorkflowExecutorCache;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RootWorkflowThreadImpl extends WorkflowThreadImpl {
private static final Logger log = LoggerFactory.getLogger(RootWorkflowThreadImpl.class);

RootWorkflowThreadImpl(
WorkflowThreadExecutor workflowThreadExecutor,
SyncWorkflowContext syncWorkflowContext,
DeterministicRunnerImpl runner,
@Nonnull String name,
int priority,
boolean detached,
CancellationScopeImpl parentCancellationScope,
Runnable runnable,
WorkflowExecutorCache cache,
List<ContextPropagator> contextPropagators,
Map<String, Object> propagatedContexts) {
super(
workflowThreadExecutor,
syncWorkflowContext,
runner,
name,
priority,
detached,
parentCancellationScope,
runnable,
cache,
contextPropagators,
propagatedContexts);
}

@Override
public void yield(String reason, Supplier<Boolean> unblockCondition)
throws DestroyWorkflowThreadError {
log.warn(
"Detected root workflow thread yielding {}. This can happen by making blocking calls during workflow instance creating, such as executing an activity inside a @WorkflowInit constructor. This can cause issues, like Queries or Updates rejection because the workflow instance creation is delayed",
getName());
super.yield(reason, unblockCondition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
* thrown by the constructor are treated the same as exceptions thrown by the workflow method.
*
* <p>Workflow initialization methods are called before the workflow method, signal handlers, update
* handlers or query handlers.
* handlers or query handlers. Users should be careful not to block in constructors. Blocking in the
* constructor will delay handling of the workflow method and signal handlers, and cause rejection
* of the update and query handlers.
*
* <p>This annotation applies only to workflow implementation constructors.
*/
Expand Down
Loading