Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Fixed error that would crash host application if memcached server went away. #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/memcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var tcp = require('net'),

var crlf = "\r\n";
var crlf_len = crlf.length;
var self;

var error_replies = ['ERROR', 'NOT_FOUND', 'CLIENT_ERROR', 'SERVER_ERROR'];

Expand All @@ -47,7 +48,7 @@ util.inherits(Client, process.EventEmitter);
Client.prototype.connect = function () {
if (!this.conn) {
this.conn = new tcp.createConnection(this.port, this.host);
var self = this;
self = this;
this.conn.addListener("connect", function () {
this.setTimeout(0); // try to stay connected.
this.setNoDelay();
Expand Down Expand Up @@ -107,7 +108,12 @@ Client.prototype.dispatchHandles = function() {
Client.prototype.query = function(query, type, callback) {
this.callbacks.push({ type: type, fun: callback });
this.sends++;
this.conn.write(query + crlf);
if (this.conn !== null) {
this.conn.write(query + crlf);
} else {
// Server has crashed or in another way become unavailable, connection closed.
self.emit("close");
}
};

Client.prototype.close = function() {
Expand Down