Running into an issue when creating namespace programmatically

I am creating namespace programmatically

       Worker workflowWorker = workerFactory.newWorker(WORKFLOW_TASK_QUEUE);

         * Register namespace if not exists on the temporal server. This logic is behind a feature flag.
        final boolean autoRegisterNamespace =
            (boolean)environment.getProperty("temporal.namespace.autoregister", Boolean.class, DEFAULT_NAMESPACE_AUTOREGISTER); // registration behind boolean flag
        if (autoRegisterNamespace) {
            RegisterNamespaceRequest request = RegisterNamespaceRequest.newBuilder()
                                                                                   ? ArchivalState.ARCHIVAL_STATE_ENABLED
                                                                                   : ArchivalState.ARCHIVAL_STATE_DISABLED)
                                                                                   ? ArchivalState.ARCHIVAL_STATE_ENABLED
                                                                                   : ArchivalState.ARCHIVAL_STATE_DISABLED)

However I am getting this exception
io.grpc.StatusRuntimeException: NOT_FOUND: namespace: hello-world not found


{"@timestamp":"2021-08-24T21:26:00.920+00:00","@version":"1","message":"Failure in thread Host Local Workflow Poller: 3","

logger_name":"io.temporal.internal.worker.Poller","thread_name":"Host Local Workflow Poller: 3","level":"ERROR","level_val

ue":40000,"stack_trace":"io.grpc.StatusRuntimeException: NOT_FOUND: namespace: hello-world not found\n\tat io.grpc.stub.ClientC

alls.toStatusRuntimeException(\n\tat io.grpc.stub.ClientCalls.getUnchecked(\n\ta

t io.grpc.stub.ClientCalls.blockingUnaryCall(\n\tat io.temporal.api.workflowservice.v1.WorkflowServic

eGrpc$WorkflowServiceBlockingStub.pollWorkflowTaskQueue(\n\tat io.temporal.internal.worker.W

orkflowPollTask.poll(\n\tat io.temporal.internal.worker.WorkflowPollTask.poll(WorkflowPollTask.ja

va:37)\n\tat io.temporal.internal.worker.Poller$\n\tat io.temporal.internal.worker.P


java:25)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(\n\tat java.base/j

ava.util.concurrent.ThreadPoolExecutor$\n\tat java.base/


I wonder if this is due to the fact that the activities and workflow are registered prior to creating the namespace. If yes, when should one ideally call the logic to create namespace programmatically ?

You usually create a namespace from a separate process or tctl before starting your workers.

But I believe that the error you posted should go away after 10 seconds which is the time it takes for the namespace cache to be updated.

Strangeā€¦ I saw this exception for a couple of hours on the temporal instance. @maxim

Did restarting workers help? Did you see the namespace in the tctl namespace describe?

Hi @maxim
I have a similar requirement, where just after creating the namespace , I need to start the worker.
but I am getting this error :

2021-11-30 19:32:59,390 [Host Local Workflow Poller: 3] ERROR io.temporal.internal.worker.Poller - Failure in thread Host Local Workflow Poller: 3
io.grpc.StatusRuntimeException: NOT_FOUND: namespace: tenant14 not found

How can that be done programmatically ? should I add Thread sleep after registering the namespace?
Can I refresh the namespace cache manually ?

Yes, there is a delay similar to when adding new search attributes, from when the request is made to when the namespace is created. I think the same recommendation applies as to search attribute creation, to wait 1 minute after request and then start using it. This is current limitation that we will address in the future.

You can use DescribeNamespaceRequest to check if the namespace exists (this should throw StatusRuntimeException if it does not):

try {
            DescribeNamespaceResponse resp = client.getWorkflowServiceStubs().blockingStub().describeNamespace(

        } catch(StatusRuntimeException e) {
            // ....

To list namespaces, you can do for example:

ListNamespacesResponse response = client.getWorkflowServiceStubs().blockingStub().listNamespaces(
        List<DescribeNamespaceResponse> namespaces = response.getNamespacesList();
        for(DescribeNamespaceResponse nr : namespaces) {