Skip to content

Client connection stops working if server ip changesΒ #179

@benzman81

Description

@benzman81

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions