memcachier / memjs

A memcache client for node using the binary protocol and SASL authentication
MIT License
195 stars 52 forks source link

Application exits if memcached server restarts #162

Open varju opened 2 years ago

varju commented 2 years ago

If the memcached server is restarted after the client has already opened a socket connection, the next client request causes the application to exit.

Note that this problem only seems to occur when using a remote memcached server, e.g. in a remote Docker server. I have not been able to reproduce when running locally.

Sample code that helps demonstrate the problem:

const memjs = require('memjs');

async function main() {
  const client = memjs.Client.create('remote.docker.host');

  let i = 0;
  while (true) {
    try {
      i++;

      const key = `Record${i}`;
      console.log(`Storing ${key}`);
      await client.set(key, 'value');

      const result = await client.get(key);
      const value = result && result.value ? result.value.toString() : null;
      console.log(`Loaded ${key}=${value}`);
    } catch (e) {
      console.log('Loop failed', e);
    }
  }
}

main().then(() => {
  console.log('Done');
}).catch(e => {
  console.log('Failed', e);
});

While this is running, docker restart memcached on the remote server and you should see the process exit with no errors.

cannikin commented 2 years ago

Any updates on this one? I'm trying to added Memjs to RedwoodJS and I'm seeing something similar: if the memcached server goes away the next request just hangs forever. :(