@@ -3,7 +3,7 @@ import type { InterfaceAbi } from 'ethers'
33import { Interface , WebSocketProvider , ethers } from 'ethers'
44import { WebSocket } from 'ws'
55import type { ErrorEvent } from 'ws'
6- import { type ContractAddress , isInstanceof , to } from '@ora-io/utils'
6+ import { type ContractAddress , isInstanceof , timeout , to } from '@ora-io/utils'
77import { debug } from '../debug'
88import { RekuContractManager } from './contract'
99
@@ -217,18 +217,14 @@ export class RekuProviderManager {
217217 debug ( 'heartbeat running...' )
218218 const hasProvider = this . _hasProvider ( )
219219 debug ( 'heartbeat has provider: %s' , hasProvider )
220- this . _provider ?. send ( 'net_version' , [ ] )
221- . then ( ( res ) => {
222- debug ( 'heartbeat response: %s' , res )
223- } )
224- . catch ( ( err ) => {
225- this . reconnect ( )
226- this . _event ?. emit ( 'error' , err )
227- debug ( 'heartbeat error: %s' , err )
228- } )
229- . finally ( ( ) => {
230- debug ( 'heartbeat finally' )
231- } )
220+
221+ const [ err , res ] = await to ( timeout ( async ( ) => this . _provider ?. send ( 'net_version' , [ ] ) , 10 * 1000 ) )
222+ if ( err ) {
223+ this . reconnect ( )
224+ this . _event ?. emit ( 'error' , err )
225+ debug ( 'heartbeat timeout error: %s' , err )
226+ }
227+ else { debug ( 'heartbeat response: %s' , res ) }
232228 }
233229 else {
234230 debug ( 'heartbeat destroyed' )
0 commit comments