异步函数停止处理并且无法仅在生产 aws ec2 集群上抛出 exc
Async function stops processing and fails to throw exc only on production aws ec2 cluster
当我将以下代码部署到我的生产站点时,我 运行 遇到了无法解释的错误情况。在本地,所有这些功能都经过测试并且可以正常工作。
我已经尝试深入了解它似乎失败的承诺,但它们不会触发任何异常。 usersApiGateway.getNonce 是一个获取请求,当我在 POSTMAN 上发送获取请求时,我验证了我得到了正确的 return 值。
在我的 AWS 日志上,它基本上显示它一直执行到下面指定的点,然后就停止了。然后大约 10 分钟后,它停止尝试通过 asyncTimeout 调用进程,然后永久卡住。感谢任何有关我如何找到根本原因的帮助。
违规函数:
async createBuyOrder(tokenAddress, amountSell, amountBuy) {
amountSell = new BigNumber(amountSell);
amountBuy = new BigNumber(amountBuy);
let nonce = '';
[amountBuy, amountSell, nonce] = await Promise.all([
web3Service.convertToWei(tokenAddress, amountBuy),
web3Service.convertToWei(ETHER_ADDRESS, amountSell),
usersApiGateway.getNonce(this.adminAccount)
]);
// FUNCTION FAILS TO RETURN ANYTHING AFTER THIS POINT
// Console.log for nonce, amount buy/sell/buy order below fail to show up
// that is what I mean by not working
const buyOrder = {
"addressBuy" : tokenAddress,
"amountBuy" : amountBuy,
"addressSell": ETHER_ADDRESS,
"amountSell" : amountSell,
"nonce" : nonce,
}
await this.createOrder(buyOrder);
}
这是从这个函数调用的:
async populateOrderBook(tokenAddress, numOrders = 1) {
for(let i = numOrders; i > 0; i--) {
for(let j = -1; j < numOrders - i; j++){
try {
await this.createBuyOrder(tokenAddress, BUYORDER_amountSell, BUYORDER_amountBuy);
await this.createSellOrder(tokenAddress, SELLORDER_amountBuy, SELLORDER_amountSell);
} catch(exc) {
console.log(exc)
}
}
}
}
在 class
的 init() 函数中定期调用
asyncTimeout(async () => {
try {
await Promise.all([
this.populateOrderBook(tokenAddress, 3)
]);
} catch (exc) {
console.error('Error while populating order book from Kyber');
console.error(exc);
}
}, 60000);
我已经测试了它想要挂起的来自 web3Service 的看似有问题的功能,它似乎在本地工作得很好
async convertToWei(tokenAddress, amount) {
const numberOfDecimals = await this.tokenDecimals(tokenAddress);
return new BigNumber(toBaseUnit(amount, numberOfDecimals));
}
事实证明,我的节点与以太坊区块链的连接无法正常工作。我使用连接来确定我的 convertToWei 函数调用有多少小数位,由于连接断开,它只是陷入了一个永远无法解决的循环中。
当我将以下代码部署到我的生产站点时,我 运行 遇到了无法解释的错误情况。在本地,所有这些功能都经过测试并且可以正常工作。
我已经尝试深入了解它似乎失败的承诺,但它们不会触发任何异常。 usersApiGateway.getNonce 是一个获取请求,当我在 POSTMAN 上发送获取请求时,我验证了我得到了正确的 return 值。
在我的 AWS 日志上,它基本上显示它一直执行到下面指定的点,然后就停止了。然后大约 10 分钟后,它停止尝试通过 asyncTimeout 调用进程,然后永久卡住。感谢任何有关我如何找到根本原因的帮助。
违规函数:
async createBuyOrder(tokenAddress, amountSell, amountBuy) {
amountSell = new BigNumber(amountSell);
amountBuy = new BigNumber(amountBuy);
let nonce = '';
[amountBuy, amountSell, nonce] = await Promise.all([
web3Service.convertToWei(tokenAddress, amountBuy),
web3Service.convertToWei(ETHER_ADDRESS, amountSell),
usersApiGateway.getNonce(this.adminAccount)
]);
// FUNCTION FAILS TO RETURN ANYTHING AFTER THIS POINT
// Console.log for nonce, amount buy/sell/buy order below fail to show up
// that is what I mean by not working
const buyOrder = {
"addressBuy" : tokenAddress,
"amountBuy" : amountBuy,
"addressSell": ETHER_ADDRESS,
"amountSell" : amountSell,
"nonce" : nonce,
}
await this.createOrder(buyOrder);
}
这是从这个函数调用的:
async populateOrderBook(tokenAddress, numOrders = 1) {
for(let i = numOrders; i > 0; i--) {
for(let j = -1; j < numOrders - i; j++){
try {
await this.createBuyOrder(tokenAddress, BUYORDER_amountSell, BUYORDER_amountBuy);
await this.createSellOrder(tokenAddress, SELLORDER_amountBuy, SELLORDER_amountSell);
} catch(exc) {
console.log(exc)
}
}
}
}
在 class
的 init() 函数中定期调用 asyncTimeout(async () => {
try {
await Promise.all([
this.populateOrderBook(tokenAddress, 3)
]);
} catch (exc) {
console.error('Error while populating order book from Kyber');
console.error(exc);
}
}, 60000);
我已经测试了它想要挂起的来自 web3Service 的看似有问题的功能,它似乎在本地工作得很好
async convertToWei(tokenAddress, amount) {
const numberOfDecimals = await this.tokenDecimals(tokenAddress);
return new BigNumber(toBaseUnit(amount, numberOfDecimals));
}
事实证明,我的节点与以太坊区块链的连接无法正常工作。我使用连接来确定我的 convertToWei 函数调用有多少小数位,由于连接断开,它只是陷入了一个永远无法解决的循环中。