forta-network / forta-node

Scan Node software for the Forta Network
https://forta.org
Other
79 stars 151 forks source link

Improve nats Client Connection Logic #863

Open sergeyWh1te opened 4 months ago

sergeyWh1te commented 4 months ago

Description

The current implementation of the nats NewClient function in codebase has a few areas that need improvement for better connection management and logging. The following issues have been identified:

Redundant Connection Attempts:

Proposed Solution

  1. Simplifying Connection Logic:

    • Removing the loop for connection attempts and replacing it with a single connection attempt using NATS connection parameters such as ReconnectWait and MaxReconnects.
  2. Improving Error Handling:

    • Implementing NATS connection event handlers (DisconnectErrHandler, ReconnectHandler, and ClosedHandler) to provide detailed logs for connection lifecycle events.

    https://github.com/forta-network/forta-node/pull/862