Merge pull request #429 from shocknet/timeout-err-stack
Timeout err stack
This commit is contained in:
commit
dffc0e7252
2 changed files with 19 additions and 56 deletions
|
|
@ -101,7 +101,6 @@ const timeout2 = promise => {
|
||||||
* @returns {Promise<T>}
|
* @returns {Promise<T>}
|
||||||
*/
|
*/
|
||||||
const tryAndWait = async (promGen, shouldRetry = () => false) => {
|
const tryAndWait = async (promGen, shouldRetry = () => false) => {
|
||||||
/* eslint-disable no-empty */
|
|
||||||
/* eslint-disable init-declarations */
|
/* eslint-disable init-declarations */
|
||||||
|
|
||||||
// If hang stop at 10, wait 3, retry, if hang stop at 5, reinstate, warm for
|
// If hang stop at 10, wait 3, retry, if hang stop at 5, reinstate, warm for
|
||||||
|
|
@ -118,28 +117,15 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (shouldRetry(resolvedValue)) {
|
if (!shouldRetry(resolvedValue)) {
|
||||||
logger.info(
|
|
||||||
'force retrying' /* +
|
|
||||||
` args: ${promGen.toString()} -- ${shouldRetry.toString()} \n resolvedValue: ${resolvedValue}, type: ${typeof resolvedValue}`
|
|
||||||
*/
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return resolvedValue
|
return resolvedValue
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
if (e.message !== Constants.ErrorCode.TIMEOUT_ERR) {
|
||||||
if (e.message === Constants.ErrorCode.NOT_AUTH) {
|
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(
|
|
||||||
`\n retrying \n` /* +
|
|
||||||
` args: ${promGen.toString()} -- ${shouldRetry.toString()}`
|
|
||||||
*/
|
|
||||||
)
|
|
||||||
|
|
||||||
await delay(200)
|
await delay(200)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -150,28 +136,15 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (shouldRetry(resolvedValue)) {
|
if (!shouldRetry(resolvedValue)) {
|
||||||
logger.info(
|
|
||||||
'force retrying' /* +
|
|
||||||
` args: ${promGen.toString()} -- ${shouldRetry.toString()} \n resolvedValue: ${resolvedValue}, type: ${typeof resolvedValue}`
|
|
||||||
*/
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return resolvedValue
|
return resolvedValue
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
if (e.message !== Constants.ErrorCode.TIMEOUT_ERR) {
|
||||||
if (e.message === Constants.ErrorCode.NOT_AUTH) {
|
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(
|
|
||||||
`\n retrying \n` /* +
|
|
||||||
` args: ${promGen.toString()} -- ${shouldRetry.toString()}`
|
|
||||||
*/
|
|
||||||
)
|
|
||||||
|
|
||||||
await delay(3000)
|
await delay(3000)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -182,32 +155,22 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (shouldRetry(resolvedValue)) {
|
if (!shouldRetry(resolvedValue)) {
|
||||||
logger.info(
|
|
||||||
'force retrying' /* +
|
|
||||||
` args: ${promGen.toString()} -- ${shouldRetry.toString()} \n resolvedValue: ${resolvedValue}, type: ${typeof resolvedValue}`
|
|
||||||
*/
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return resolvedValue
|
return resolvedValue
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
if (e.message !== Constants.ErrorCode.TIMEOUT_ERR) {
|
||||||
if (e.message === Constants.ErrorCode.NOT_AUTH) {
|
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(
|
return timeout10(
|
||||||
`\n NOT recreating a fresh gun but retrying one last time \n` /* +
|
promGen(
|
||||||
` args: ${promGen.toString()} -- ${shouldRetry.toString()}`
|
require('../../Mediator/index').getGun(),
|
||||||
*/
|
require('../../Mediator/index').getUser()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
const { gun, user } = require('../../Mediator/index').freshGun()
|
|
||||||
|
|
||||||
return timeout10(promGen(gun, user))
|
|
||||||
/* eslint-enable no-empty */
|
|
||||||
/* eslint-enable init-declarations */
|
/* eslint-enable init-declarations */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2725,16 +2725,16 @@ module.exports = async (
|
||||||
: gun
|
: gun
|
||||||
keys.forEach(key => (node = node.get(key)))
|
keys.forEach(key => (node = node.get(key)))
|
||||||
|
|
||||||
return new Promise(res => {
|
return new Promise((res, rej) => {
|
||||||
const listener = async data => {
|
const listener = data => {
|
||||||
if (publicKeyForDecryption) {
|
if (publicKeyForDecryption) {
|
||||||
res(
|
GunWriteRPC.deepDecryptIfNeeded(
|
||||||
await GunWriteRPC.deepDecryptIfNeeded(
|
|
||||||
data,
|
data,
|
||||||
publicKeyForDecryption,
|
publicKeyForDecryption,
|
||||||
epubForDecryption
|
epubForDecryption
|
||||||
)
|
)
|
||||||
)
|
.then(res)
|
||||||
|
.catch(rej)
|
||||||
} else {
|
} else {
|
||||||
res(data)
|
res(data)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue