Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
enforce only one call to run from callback
Browse files Browse the repository at this point in the history
fixes enforce only one call to `run` from callback

also, re-enable publisherInfo.synopsis reporting if
`LEDGER_PUBLISHER_DEBUG=true`

auditor: @diracdeltas
  • Loading branch information
mrose17 committed Sep 4, 2016
1 parent e0d9c8a commit 20596da
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var boot = () => {
bootP = false
return console.log('ledger client boot error: ' + ex.toString() + '\n' + ex.stack)
}
if (client.sync(callback) === true) run(random.randomInt({ min: 1, max: 10 * msecs.minute }))
if (client.sync(callback) === true) run(random.randomInt({ min: 1, max: 10 }) * msecs.minute)
getBalance()

bootP = false
Expand Down Expand Up @@ -358,9 +358,7 @@ var initialize = (onoff) => {
} catch (ex) {
return console.log('ledger client creation error: ' + ex.toString() + '\n' + ex.stack)
}
if (client.sync(callback) === true) {
run(random.randomInt({ min: 1, max: (state.options.debugP ? 5 * msecs.second : 1 * msecs.minute) }))
}
if (client.sync(callback) === true) run(random.randomInt({ min: 1, max: 10 }) * msecs.minute)
cacheRuleSet(state.ruleset)

// Make sure bravery props are up-to-date with user settings
Expand Down Expand Up @@ -469,7 +467,6 @@ var updatePublisherInfo = () => {
syncWriter(pathName(synopsisPath), synopsis, () => {})
publisherInfo.synopsis = synopsisNormalizer()

/*
if (publisherInfo._internal.debugP) {
data = []
publisherInfo.synopsis.forEach((entry) => {
Expand All @@ -478,7 +475,6 @@ var updatePublisherInfo = () => {

console.log('\nupdatePublisherInfo: ' + JSON.stringify(data, null, 2))
}
*/

appActions.updatePublisherInfo(underscore.omit(publisherInfo, [ '_internal' ]))
}
Expand Down Expand Up @@ -883,10 +879,10 @@ var roundtrip = (params, options, callback) => {
if (options.payload) console.log('<<< ' + JSON.stringify(params.payload, null, 2).split('\n').join('\n<<< '))
}

var run0P = false
var timeoutId = false

var run = (delayTime) => {
if (clientOptions.verboseP) console.log('\nledger client run: clientP=' + (!!client) + ' delayTime=' + delayTime)
// if (clientOptions.verboseP) console.log('\nledger client run: clientP=' + (!!client) + ' delayTime=' + delayTime)

if ((typeof delayTime === 'undefined') || (!client)) return

Expand Down Expand Up @@ -914,23 +910,25 @@ var run = (delayTime) => {
try {
delayTime = client.timeUntilReconcile()
} catch (ex) {
delayTime = random.randomInt({ min: 1, max: 10 * msecs.minute })
delayTime = false
}
if (delayTime === false) delayTime = 0
if (delayTime === false) delayTime = random.randomInt({ min: 1, max: 10 }) * msecs.minute
}
if (delayTime > 0) {
if (timeoutId) return console.log('\ninterception')

active = client
if (run0P) return console.log('suppress run0')
if (delayTime > msecs.day) delayTime = msecs.day

run0P = true
return setTimeout(() => {
run0P = false
timeoutId = setTimeout(() => {
timeoutId = false
if (active !== client) return

if (!client) return console.log('\n\n*** MTR says this can\'t happen(1)... please tell him that he\'s wrong!\n\n')

if (client.sync(callback) === true) return run(0)
}, delayTime)
return
}

if (client.isReadyToReconcile()) return client.reconcile(uuid.v4().toLowerCase(), callback)
Expand Down

1 comment on commit 20596da

@mrose17
Copy link
Member Author

@mrose17 mrose17 commented on 20596da Sep 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes #3702

Please sign in to comment.