nknorg / nkn-sdk-js

JavaScript Implementation of NKN Client and Wallet SDK
Apache License 2.0
43 stars 17 forks source link

运行example中的client.js失败,Error: Challenge timeout #113

Closed SteveCruise closed 1 year ago

SteveCruise commented 1 year ago

nkn-sdk: v1.2.7

Secret seed: 4fafbc6eac41bd476dea6878094ad7bc2ea52a9a2fa9a88dbaaeb5659737cb32
C:\Users\xxx\Projects\xxx\node_modules\nkn-sdk\lib\client\client.js:700
        reject(new Error('Challenge timeout'));
               ^

Error: Challenge timeout
    at Timeout._onTimeout (C:\Users\xxx\Projects\xxx\node_modules\nkn-sdk\lib\client\client.js:700:16)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7)

Node.js v18.15.0
SteveCruise commented 1 year ago

nkn-sdk: v1.2.8

经常遇到这样的问题,然后程序就退出了。是因为在中国连接外国nkn节点不稳定的原因吗? nkn-sdk-go里面有ConnectRetries参数,可以程序不退出一直连,nkn-sdk-js里面没有这样的参数,怎么办?

nkn.NewMultiClient(account, "", 4, false, &nkn.ClientConfig{ConnectRetries: 10000})
yilunzhang commented 1 year ago

这个问题在最新版 1.2.8 中应该不会出现了,你确定运行的是 1.2.8 版吗?

SteveCruise commented 1 year ago

这个问题在最新版 1.2.8 中应该不会出现了,你确定运行的是 1.2.8 版吗?

看了package.json, 是1.2.9呢 在lib\client\client.js:706:16,断网就会触发reject(new common.errors.ChallengeTimeoutError())

    let challengeHandler = new Promise((resolve, reject) => {
      challengeDone = resolve;
      setTimeout(() => {
        reject(new common.errors.ChallengeTimeoutError());
      }, consts.waitForChallengeTimeout);
    });

居然部分文件不更新,删掉nkn-sdk重新下载就是1.2.9的新代码了,没有这个问题了,喜欢这种自动重连的感觉

WebSocket unexpectedly closed.
Reconnecting in 1s...
WebSocket unexpectedly closed.
Reconnecting in 1s...
WebSocket unexpectedly closed.
Reconnecting in 1s...
WebSocket unexpectedly closed.
Reconnecting in 1s...
RPC call failed, RpcTimeoutError: rpc timeout
    at rpcCall (C:\Users\xxx\Projects\xxx\node_modules\nkn-sdk\lib\common\rpc.js:121:13)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:538:9)
    at process.processTimers (node:internal/timers:512:7)
    at async Client._connect (C:\Users\xxx\Projects\xxx\node_modules\nkn-sdk\lib\client\client.js:162:15)
Reconnecting in 2s...
yilunzhang commented 1 year ago

你说的这个问题我刚才仔细研究了一番,和 node 的版本有关。在高版本的 nodejs 中,unhandled promise rejection 会导致整个进程退出,有可能出现你说的问题,低版本的 nodejs 不会导致退出,所以只有日志。这个我们确实需要适配一下。

yilunzhang commented 1 year ago

v1.3.0 已修复哈

SteveCruise commented 1 year ago

感谢大神!确实又出现了,发现在lib\client\client.js里,而不是在src\client\client.js里。继续更新v1.3.0 测试