javascript - 异步函数停止处理并且无法仅在生产 aws ec2 集群上抛出 exc

标签 javascript node.js solidity web3js

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

我已经尝试深入了解它似乎失败的 promise ,但它们不会触发任何异常。 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));
   }

最佳答案

事实证明,我与以太坊区 block 链的 Node 连接无法正常工作。我使用该连接来确定我的 convertToWei 函数调用有多少位小数,但由于连接断开,它只是陷入了一个永远无法解决的循环中。

关于javascript - 异步函数停止处理并且无法仅在生产 aws ec2 集群上抛出 exc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54509178/

相关文章:

javascript - Yarn 不会构建项目

javascript - 监控所有 JavaScript 对象属性(magic getter 和 setter)

ethereum - Solidity 文件中同一文件的多次导入

ethereum - Truffle 迁移成功但未显示合约地址

javascript - 如何选择第一个td

javascript - 找出文本区域中的行是否为空

javascript - Firebase 匿名身份验证问题

javascript - node.js 中的内存使用量不会减少吗?这是怎么回事?

ethereum - 存储兼容性 : Solidity upgradable smart contract using "proxy" design pattern and changing the mapping type

php - 在 highcharts 中使用数组数据