Skip to content

Commit

Permalink
Remove retryReconnect from TCP adapters (iron-fish#1619)
Browse files Browse the repository at this point in the history
This feature was not working to begin with, and not well supported. I
will remove the rest from the IPC client once we delete the IPC client
and adapter soon.

Co-authored-by: Jason Spafford <[email protected]>
  • Loading branch information
NullSoldier and Jason Spafford authored Jun 13, 2022
1 parent 0a10db8 commit 59ddce1
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 38 deletions.
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class StopCommand extends IronfishCommand {
async start(): Promise<void> {
await this.parse(StopCommand)

await this.sdk.client.connect({ retryConnect: false }).catch((e) => {
await this.sdk.client.connect().catch((e) => {
if (e instanceof ConnectionError) {
this.exit(0)
}
Expand Down
2 changes: 0 additions & 2 deletions ironfish/src/fileStores/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export type ConfigOptions = {
rpcTcpHost: string
rpcTcpPort: number
rpcTcpSecure: boolean
rpcRetryConnect: boolean
tlsKeyPath: string
tlsCertPath: string
/**
Expand Down Expand Up @@ -266,7 +265,6 @@ export class Config extends KeyStore<ConfigOptions> {
rpcTcpHost: 'localhost',
rpcTcpPort: 8020,
rpcTcpSecure: false,
rpcRetryConnect: false,
tlsKeyPath: files.resolve(files.join(dataDir, 'certs', 'node-key.pem')),
tlsCertPath: files.resolve(files.join(dataDir, 'certs', 'node-cert.pem')),
maxPeers: 50,
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/clients/rpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export abstract class IronfishRpcClient extends IronfishClient {
onClose = new Event<[]>()

async tryConnect(): Promise<boolean> {
return this.connect({ retryConnect: false })
return this.connect()
.then(() => true)
.catch((e: unknown) => {
if (e instanceof ConnectionError) {
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/clients/secureTcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ConnectionRefusedError } from './errors'
import { IronfishTcpClient } from './tcpClient'

export class IronfishSecureTcpClient extends IronfishTcpClient {
async connectClient(): Promise<void> {
async connect(): Promise<void> {
return new Promise((resolve, reject): void => {
const onSecureConnect = () => {
client.off('secureConnection', onSecureConnect)
Expand Down
33 changes: 1 addition & 32 deletions ironfish/src/rpc/clients/tcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,25 @@ import { MessageBuffer } from '../messageBuffer'
import { ConnectionLostError, ConnectionRefusedError } from './errors'
import { IronfishRpcClient, RpcClientConnectionInfo } from './rpcClient'

const CONNECT_RETRY_MS = 2000

export class IronfishTcpClient extends IronfishRpcClient {
client: net.Socket | null = null
protected readonly host: string
protected readonly port: number
private retryConnect: boolean
private connectTimeout: SetTimeoutToken | null
isConnected = false
connection: RpcClientConnectionInfo
private messageBuffer: MessageBuffer

constructor(
host: string,
port: number,
logger: Logger = createRootLogger(),
retryConnect = false,
) {
constructor(host: string, port: number, logger: Logger = createRootLogger()) {
super(logger.withTag('tcpclient'))
this.host = host
this.port = port
this.connection = { mode: 'tcp', host: host, port: port }
this.retryConnect = retryConnect
this.connectTimeout = null
this.messageBuffer = new MessageBuffer()
}

async connect(): Promise<void> {
let connectionError: unknown
const connected = await this.connectClient()
.then(() => true)
.catch((error) => {
connectionError = error
return false
})

if (!connected) {
if (this.retryConnect) {
this.logger.warn(
`Failed to connect to ${String(this.host)}:${String(this.port)}, retrying`,
)
this.connectTimeout = setTimeout(() => void this.connect(), CONNECT_RETRY_MS)
return
}
this.logger.error(`Failed to connect to ${String(this.host)}:${String(this.port)}`)
throw connectionError
}
}

async connectClient(): Promise<void> {
return new Promise((resolve, reject): void => {
const onConnect = () => {
client.off('connect', onConnect)
Expand Down
1 change: 0 additions & 1 deletion ironfish/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export class IronfishSdk {
socketPath: config.get('ipcPath'),
},
logger,
config.get('rpcRetryConnect'),
)
}

Expand Down

0 comments on commit 59ddce1

Please sign in to comment.