Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client connection stops working if server ip changes #179

Open
benzman81 opened this issue Nov 15, 2021 · 2 comments
Open

Client connection stops working if server ip changes #179

benzman81 opened this issue Nov 15, 2021 · 2 comments

Comments

@benzman81
Copy link

If server and client are connected and the server changes its ip address (seems to happen in AWS kubernetes quite often), than the client still thinks its connected but does not receive events anymore posted to the server. The connection seems lost. Only restarting the client gets it back to work.

For now, I build a docker image statrting the client with the following script and use it in kubernetes:

const program = require('commander')
const SmeeClient = require('smee-client')

program
  .version("0.0.1", '-v, --version')
  .usage('[options]')
  .option('-u, --url <url>', 'URL of the webhook proxy service. Default: https://smee.io/new')
  .option('-t, --target <target>', 'Full URL (including protocol and path) of the target service the events will forwarded to. Default: http://127.0.0.1:PORT/PATH')
  .parse(process.argv)

if(!program.url) {
    console.error("No url set. Use '-u' as argument.");
    return;
}
if(!program.target) {
    console.error("No target set. Use '-t' as argument.");
    return;
}

const smee = new SmeeClient({
    source: program.url,
    target: program.target,
    logger: console
})

const maxPingDifferenceAllowedInSeconds = 60;
const checkIntervallInSeconds = 15;
let lastPing = Date.now();

const events = smee.start()
events.addEventListener('ping', function(){
    console.log("received ping");
    lastPing = Date.now();
});

const pingDiffIntervalId = setInterval( function(){
    const pingDiff = Date.now() - lastPing;
    console.log("pingDiff: "+pingDiff);
    if((pingDiff / 1000) >= maxPingDifferenceAllowedInSeconds) {
        // Stop forwarding events
        console.error("Ping difference of server higher than allowed (pingDiff in ms: "+pingDiff+", maxPingDifferenceAllowedInSeconds"+maxPingDifferenceAllowedInSeconds+")");
        events.close()
        clearInterval(pingDiffIntervalId);
    }
}, checkIntervallInSeconds * 1000);

This script frequently checks if the client is still receiving the ping event, which it doesnt when the server changes the ip. If it is not received for about 60s the the client will exit. This will cause kubernetes to restart the client (pod) and thus gets the connection working again.

I think this should somehow be handled by default.

@tcbyrd
Copy link
Contributor

tcbyrd commented Dec 3, 2021

@benzman81 Thanks for the code showing how you got it working! Yeh, the smee server sends a keep alive signal every 30 seconds, which is intended to help with keeping the browser connected. I think your solution is basically what we need to do, and maybe add an option to enable a keep-alive interval since that may be something a user would want to customize? We could add the listener/handler in the start() method

Would you be willing to put together a PR with your code? Happy to review it and cut a release integrating this feature.

@ramonamis
Copy link

Hello everyone,

Is there any chance this fix can be merged and a new release can be made?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants