memcachier / memjs

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

Trying an operation after calling `.quit()` doesn't trigger any errors #172

Closed Julien-R44 closed 1 year ago

Julien-R44 commented 1 year ago

Given this piece of code :

var memjs = require('memjs')
var client = memjs.Client.create('localhost:11211')

client.quit()

client.get('hello', function(err, val) { 
  // Callback never called since we are disconnected
  console.log(err, val);
})

We never enter the get() callback because we're disconnected. I was wondering if this was a desired behavior or a bug?

saschat commented 1 year ago

Hey Julien

Good question. I looked at the code, and based on that

  1. Calling quit closes all connections (code).
  2. Calling get will create a new connection and perform the request (code).

So callbacks should be executed on get requests that happen after the quit. I suspect the reason the callback is not executed is because of the race condition between quit and get as detailed here.

To answer your question, if the callback is not called, it is a bug. If the connection is in the process of being closed, the callback should at least be called with an error.

Julien-R44 commented 1 year ago

Hey, thanks for your reply!

Yes, it's definitely that. As soon as I add a setTimeout after the client.quit then it's OK, the callback is called. I will try sending a PR

Julien-R44 commented 1 year ago

Hello, sorry, I've decided not to support memcached and to use redis instead. So i won't be able to make a PR. Feel free to close the issue

Thanks!