XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.21k stars 512 forks source link

When the rippled server stops and restart, the ripple-lib will hang up. #940

Closed RyanHubs closed 5 years ago

RyanHubs commented 6 years ago

@intelliot @sharafian

Can you help me solve this problem? Thank you

STEP1: sudo systemctl stop rippled STEP2: ripple_lib get this logs,

reqid=dd9572b6250e474a851bec002a0252e0||method=POST||url=/watchonly/balance||body={"currencyName":"XRP","addressList":["rf1GcLkC5UojaoWcfa1GZGbp9fT8L8vZLH"]}||msg=A request begin...
reqid=dd9572b6250e474a851bec002a0252e0||wsreqid=55158f7028624e88816283acff8b5e45||method=getBalances||options=["rf1GcLkC5UojaoWcfa1GZGbp9fT8L8vZLH"]||msg=WebSocket request begin...
server=ws://192.168.100.200:6006/||code=1000||OnDisconnected()
server=iZ8vb448nfpi49cy9g56g2Z||pid=7738||level=ERROR||reqid=dd9572b6250e474a851bec002a0252e0||wsreqid=55158f7028624e88816283acff8b5e45||onWebSocketError()||code=||message=websocket was closed||stack=[DisconnectedError(websocket was closed)]||at WebSocket.onDisconnect (/data/home/admin/wallet/xrp-funds/node_modules/ripple-lib/dist/npm/common/connection.js:370:24)||at Object.onceWrapper (events.js:317:30)||at emitTwo (events.js:131:20)||at WebSocket.emit (events.js:214:7)||at WebSocket.emitClose (/data/home/admin/wallet/xrp-funds/node_modules/ws/lib/WebSocket.js:211:10)||at _receiver.cleanup (/data/home/admin/wallet/xrp-funds/node_modules/ws/lib/WebSocket.js:199:39)||at Receiver.cleanup (/data/home/admin/wallet/xrp-funds/node_modules/ws/lib/Receiver.js:520:15)||at WebSocket.finalize (/data/home/admin/wallet/xrp-funds/node_modules/ws/lib/WebSocket.js:199:20)||at emitNone (events.js:111:20)||at Socket.emit (events.js:208:7)||at endReadableNT (_stream_readable.js:1064:12)||at _combinedTickCallback (internal/process/next_tick.js:138:11)||at process._tickDomainCallback (internal/process/next_tick.js:218:9)
reqid=dd9572b6250e474a851bec002a0252e0||wsreqid=55158f7028624e88816283acff8b5e45||method=getBalances||body={"code":"3000","data":{"message":"websocket was closed"},"msg":"WebSocket Close Unnormal","sub_code":"0002","success":false}||cost=6ms||msg=WebSocket request end.
reqid=a3f80dc44b574af78a434266cf86fe5c||method=POST||url=/watchonly/balance||body={"currencyName":"XRP","addressList":["rf1GcLkC5UojaoWcfa1GZGbp9fT8L8vZLH"]}||msg=A request begin...
reqid=a3f80dc44b574af78a434266cf86fe5c||wsreqid=07ce0881d78b4688a599a9fa269f7276||method=getBalances||options=["rf1GcLkC5UojaoWcfa1GZGbp9fT8L8vZLH"]||msg=WebSocket request begin...
<<<No response can be obtained , must restart process.>>>

STEP3: I use the ripple-lib in my program. Is there any configuration correctly?

const Remote                           = require("ripple-lib").RippleAPI;
const {node: {server, timeout}}  = require("config");
const remote                            = new Remote({server, timeout,});

remote.on("error", (code, msg) => {
    logger.info(`server=${server}||code=${code}||msg=${msg}||OnError()`);
});
remote.on("connected", () => {
    logger.info(`server=${server}||OnConnected()`);
});
remote.on("disconnected", (code) => {
    logger.info(`server=${server}||code=${code}||OnDisconnected()`);
});

class RemoteConn {
    static async init() {
        await remote.connect().catch(utilImp.onExceptionError);
    }

    static async close() {
        return await remote.disconnect().catch(utilImp.onExceptionError);
    }

    static isConnected() {
        return remote.isConnected();
    }

    static async request(parameter, method, ...options) {
        const start   = Date.now();
        const wsreqid = utilImp.get32UUIDString();
        let reqTrace  = {
            reqid:   parameter.reqid,
            wsreqid,
            method,
            options: JSON.stringify(options || null),
            msg:     "WebSocket request begin...",
        };
        logger.info(reqTrace);

        let result;
        try {
            result = await remote[method].apply(remote, options);
        } catch (err) {
            let {code, subCode} = errImp.getWebsocketErrorCode(err);
            if (err) err.reqid = `${parameter.reqid}||wsreqid=${wsreqid}||onWebSocketError()`;
            result = errImp.getExceptionData(code, subCode, err);
        } finally {
            const ms     = Date.now() - start;
            let resTrace = {
                reqid: parameter.reqid,
                wsreqid,
                method,
                body:  JSON.stringify(result),
                cost:  `${ms}ms`,
                msg:   "WebSocket request end.",
            };
            logger.info(resTrace);
        }
        return result;
    }
    }
FKSRipple commented 5 years ago

Closing stale issues. This is expected behavior, you'll need to manually reconnect if the server disconnects you (see: https://github.com/ripple/ripple-lib/blob/develop/src/common/connection.ts#L444-L448)