# Connection retry for temporal

**URL:** <https://community.temporal.io/t/connection-retry-for-temporal/10992>\
**Category:** Community Support\
**Tags:** typescript-sdk\
**Created:** [February 13, 2024, 8:17am UTC](https://community.temporal.io/t/connection-retry-for-temporal/10992 "2024-02-13T08:17:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul1](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/rahul1/32/4945_2.png) [@Rahul1](https://community.temporal.io/u/Rahul1)\
**Post date:** [February 13, 2024, 8:17am UTC](https://community.temporal.io/t/connection-retry-for-temporal/10992/1 "2024-02-13T08:17:00Z")

</div>

Hi i have installed temporal in my linux system and i use the temporal server start-dev command to run a development cluster  
My application is in nestjs and i have written a provider file to connect to this cluster  
The code for the file is given as below :

```auto
export const TemporalClientProvider: Provider = {
  provide: TEMPORAL_CLIENT,
  inject: [LoggerService, ConfigService],
  async useFactory(logger: LoggerService, configService: ConfigService) {
    try {
      const connection = await Connection.connect({
        address: `${configService.get('TEMPORAL_CLUSTER_IP_ADDRESS')}:${
          configService.get('TEMPORAL_CLUSTER_PORT') || '7233'
        }`,
      });
      return new WorkflowClient({
        connection,
        namespace: configService.get('TEMPORAL_CLUSTER_NAMESPACE'),
      });
    } catch (err) {
      logger.error(`Failed to connect to the temporal server. Error - ${err}`);
    }
  },
};

```

Here the namespace is given as default, now when i suddenly exit from my temporal in the terminal, i keep getting a temporal connection refused log again and again given as below

```auto
2024-02-13T06:45:05.430569Z WARN temporal_client::retry: gRPC call poll_workflow_task_queue retried 8 times error=Status { code: Unavailable, message: "error trying to connect: tcp connect error: Connection refused (os error 111)", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })))) }
2024-02-13T06:45:05.529139Z WARN temporal_client::retry: gRPC call poll_workflow_task_queue retried 8 times error=Status { code: Unavailable, message: "error trying to connect: tcp connect error: Connection refused (os error 111)", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })))) }
2024-02-13T06:45:05.760595Z WARN temporal_client::retry: gRPC call poll_workflow_task_queue retried 8 times error=Status { code: Unavailable, message: "error trying to connect: tcp connect error: Connection refused (os error 111)", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })))) }
2024-02-13T06:45:05.954094Z WARN temporal_client::retry: gRPC call poll_activity_task_queue retried 8 times error=Status { code: Unavailable, message: "error trying to connect: tcp connect error: Connection refused (os error 111)", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })))) }
2024-02-13T06:45:06.179704Z WARN temporal_client::retry: gRPC call poll_activity_task_queue retried 8 times error=Status { code: Unavailable, message: "error trying to connect: tcp connect error: Connection refused (os error 111)", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })))) }
2024-02-13T06:45:06.337474Z WARN temporal_client::retry: gRPC call poll_activity_task_queue retried 8 times error=Status { code: Unavailable, message: "error trying to connect: tcp connect error: Connection refused (os error 111)", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })))) }
2024-02-13T06:45:06.508890Z WARN temporal_client::retry: gRPC call poll_workflow_task_queue retried 8 times error=Status { code: Unavailable, message: "error trying to connect: tcp connect error: Connection refused (os error 111)", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })))) }

```

I can write a process.exit(1) in the catch of the provider to exit from this, but what i want is i want to have a retry mechanism where after a set number of attempts, it gets exited and also we should start to connect again if we run the app again

Are there any such available retry techniques for typescript?

Thanks and Regards,  
Rahul

---

<div class="post-metadata">

**Author:** ![bergundy](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/bergundy/32/900_2.png) [@bergundy](https://community.temporal.io/u/bergundy)\
**Post date:** [February 22, 2024, 5:28pm UTC](https://community.temporal.io/t/connection-retry-for-temporal/10992/2 "2024-02-22T17:28:03Z")

</div>

You should catch the `Worker.run` promise rejection and handle that appropriately.

If you want the application to quit, that’s where you’ll want to exit.

I noticed the nextjs plugin doesn’t handle this properly, you may need to address it there.

> <https://github.com/KurtzL/nestjs-temporal/blob/5ef91f4e6d3a0ee25a729f091adbdf318e722283/lib/temporal.explorer.ts#L62>

You’ll want the application to wait until `run` resolves before exiting the process for graceful shutdown.
