Skip to content

Commit fb6d2b5

Browse files
authored
Merge pull request #275 from EdgeApp/sam/fix-server-reconnect
Fix broken reconnect for makeServerStates
2 parents 01b04c6 + a5506cf commit fb6d2b5

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/common/utxobased/engine/makeServerStates.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ interface ServerState {
2323

2424
interface ServerStateConfig {
2525
engineEmitter: EngineEmitter
26-
engineStarted: boolean
2726
log: EdgeLog
2827
pluginInfo: PluginInfo
2928
pluginState: PluginState
@@ -61,18 +60,11 @@ interface Connections {
6160
}
6261

6362
export function makeServerStates(config: ServerStateConfig): ServerStates {
64-
const {
65-
engineEmitter,
66-
engineStarted,
67-
log,
68-
pluginInfo,
69-
pluginState,
70-
walletInfo
71-
} = config
63+
const { engineEmitter, log, pluginInfo, pluginState, walletInfo } = config
7264
log('Making server states')
7365

7466
let serverStates: ServerStateCache = {}
75-
67+
let isEngineOn: boolean = true
7668
let connections: Connections = {}
7769
let serverList: string[] = []
7870
let reconnectCounter = 0
@@ -159,6 +151,7 @@ export function makeServerStates(config: ServerStateConfig): ServerStates {
159151
}
160152

161153
const stop = async (): Promise<void> => {
154+
isEngineOn = false
162155
log(`stopping server states`)
163156
removeIdFromQueue(walletInfo.id)
164157
clearTimeout(reconnectTimer)
@@ -172,13 +165,13 @@ export function makeServerStates(config: ServerStateConfig): ServerStates {
172165
}
173166

174167
const reconnect = (): void => {
175-
if (engineStarted) {
176-
if (reconnectCounter < 5) reconnectCounter++
168+
if (isEngineOn) {
177169
log(`attempting server reconnect number ${reconnectCounter}`)
170+
const reconnectionDelay = Math.max(5, reconnectCounter++) * 1000
178171
reconnectTimer = setTimeout(() => {
179172
clearTimeout(reconnectTimer)
180173
refillServers()
181-
}, reconnectCounter * 1000)
174+
}, reconnectionDelay)
182175
}
183176
}
184177

src/common/utxobased/engine/makeUtxoEngineState.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,16 @@ export function makeUtxoEngineState(
149149
}
150150
}
151151

152-
const engineStarted = false
153152
const lock = new AwaitLock()
154153

155154
const serverStates = makeServerStates({
155+
engineEmitter: emitter,
156+
log,
156157
pluginInfo,
157-
engineStarted,
158-
walletInfo,
159158
pluginState,
160-
engineEmitter: emitter,
161-
log
159+
walletInfo
162160
})
163161
const commonArgs: CommonArgs = {
164-
engineStarted,
165162
pluginInfo,
166163
walletInfo,
167164
walletTools,
@@ -439,7 +436,6 @@ export function makeUtxoEngineState(
439436
}
440437

441438
interface CommonArgs {
442-
engineStarted: boolean
443439
pluginInfo: PluginInfo
444440
walletInfo: NumbWalletInfo
445441
walletTools: UTXOPluginWalletTools

0 commit comments

Comments
 (0)