rxdb icon indicating copy to clipboard operation
rxdb copied to clipboard

replicateWithWebsocketServer prints endless connection errors although state is canceled

Open koh-osug opened this issue 10 months ago • 4 comments

In my error logic I want to stop the replication and use the cancel function of the RxReplicationState. The implementation still continuously prints:

WAS CLIENT GOT ERROR: connect ECONNREFUSED 127.0.0.1:1235

Although the server on the other end is terminated and will also never be started again in my case this error is printed forever.

How to stop the replication attempts and close the web socket behind?

This is my code to connect a client to the replication server:

 const serverState = await replicateWithWebsocketServer({
        collection: collection,
        url: `ws://${ipAddress}:${port}/socket`,
        waitForLeadership: false
    });
    serverState.error$.subscribe(async (err) => {
        logger.error({
            collection: collection.name,
            ipAddress: ipAddress,
            port: port,
            err: err.message
        }, "error in replication server connection");
        await serverState.cancel();
    })

The cancel function should also disconnect from the server or the RxReplicationState should allow to close the web socket.

koh-osug avatar Apr 13 '24 23:04 koh-osug

I see that in 15.7.0 RxReplicationState.remove. For my purposes a RxReplicationState.stop to close the web sockets would be most likely the solution. What is the idea behind to leave the web socket open?

koh-osug avatar Apr 15 '24 13:04 koh-osug

My fix is to make the websocketClient part of the options similar to what can already be done for the replication server:

https://github.com/pubkey/rxdb/compare/master...koh-osug:rxdb:master#diff-8395abd4c40a2116444ebd5daf4c5f307401693b498faa62513decf879ee2c9f

Now I can close the socket manually and the replication client can be terminated.

koh-osug avatar Apr 16 '24 03:04 koh-osug

The socket should stop retrying the connection when there is no more active replication state. Please make a PR.

pubkey avatar Apr 17 '24 10:04 pubkey

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. If you still have a problem, make a PR with a test case or to prove that you have tried to fix the problem. Notice that only bugs in the rxdb premium plugins are ensured to be fixed by the maintainer. Everything else is expected to be fixed by the community, likely you must fix it by yourself.

stale[bot] avatar Apr 29 '24 13:04 stale[bot]

Issues are autoclosed after some time. If you still have a problem, make a PR with a test case or to prove that you have tried to fix the problem.

stale[bot] avatar May 20 '24 14:05 stale[bot]