首页 > 解决方案 > 异步函数停止处理并且无法仅在生产 aws ec2 集群上抛出 exc

问题描述

当我将以下代码部署到我的生产站点时,我遇到了无法解释的错误情况。在本地,所有这些功能都经过测试并且可以正常工作。

我已经尝试深入了解似乎失败的承诺,但它们不会触发任何异常。usersApiGateway.getNonce 是一个 get 请求,当我在 POSTMAN 上发送 get 请求时,我验证了我得到了正确的返回值。

在我的 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)
          }
    }
  }
}

在类的 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));
   }

标签: javascriptnode.jssolidityweb3web3js

解决方案


事实证明,我与以太坊区块链的节点连接不起作用。我使用连接来确定我的 convertToWei 函数调用的小数位数,并且由于连接断开,它只是陷入了一个永远无法解决的循环中。


推荐阅读