question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reconnect on connection closed

See original GitHub issue

We are building an upload tool that must be resilient to connection loss. Right now when the connection is lost while an append or put operation is in progress, we get a “close” event, but the append or put operations don’t resolve or throw. Currently I’m wrapping our upload as such:

    try {
      const success = await new Promise<boolean>(resolv => {
        const listener = (s: boolean) => {
          this.client.removeListener("close", listener);
          resolv(s);
        };
        this.client.on("close", () => listener(false));

        // If the connection is lost, neither of these ever resolve.
        if (tryCont) {
          this.client.append(stream, destFile).then(() => listener(true));
        } else {
          this.client.put(stream, destFile).then(() => listener(true));
        }
      });

      if (!success) throw new Error("Connection lost");

    } catch (e) {
      console.log(e);
      throw e;
    }

This works, but feels like its leaking in the append and put calls since they are not resolving.

Along the same lines, calling connect multiple times to test for a connection results in the sftp server erroring out with a long list of “no more sessons” errors when a connection is finally made. Its like each failed connect call finally makes a connection even when it reports failure when its initially called. Is there an intended approach for doing this kind of thing? Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:22 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
theophilusxcommented, Mar 14, 2020

Yes, I think your right. Once we have exhausted all attemptw and done the error callback, we should just return. Have added it.

1reaction
james-pellowcommented, Mar 13, 2020

Looking at the code, it appears to me that there should be a return after line 111 in index.js. If there is an error, we shouldn’t continue on after the callback is executed. Does that look right to you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reconnect to websocket after close connection [duplicate]
A better method would be to have the server close the connection. This way the websocket will fire an onclose event but will...
Read more >
How to reconnect after: ConnectionClosed: code 1006 ...
Hi, I'm still new to python and websockets and can't figure this out. I am connected to two websockets. After a while, one...
Read more >
Connection closed after x minutes - HiveMQ Cloud
I am sending “ping” push messages to keep the connection open indefinitely. However the connection is closed after seemingly unrelated time ...
Read more >
V3 console live data: Stream connection closed/reconnected ...
I have a LoPy4 transmitting a couple of bytes at 30 minute intervals, being received by my TTIG gateway (registered in v2). The...
Read more >
Understanding and Handling Connection Lifetime Events in ...
If the attempts to reconnect are unsuccessful and the disconnect timeout period ends, both client and server end the SignalR connection. The ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found