Skip to content

Commit

Permalink
Merge pull request #22 from makenotion/benjamin--destroy-socket-on-ti…
Browse files Browse the repository at this point in the history
…meout

Destroy() socket on timeout
  • Loading branch information
schleyfox committed Feb 14, 2024
2 parents 9137a13 + 7a521a2 commit d7ce226
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/memjs/server.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions lib/memjs/server.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Amit Levy",
"name": "memjs",
"description": "A memcache client for node using the binary protocol and SASL authentication",
"version": "1.2.4",
"version": "1.2.4-NOTION.1",
"license": "MIT",
"homepage": "http://github.com/memcachier/memjs",
"keywords": [
Expand Down
12 changes: 6 additions & 6 deletions src/memjs/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ export class Server extends events.EventEmitter {

error(err: Error) {
const errcalls = this.errorCallbacks;
// reset all states except host, port, options, username, password
this.responseBuffer = Buffer.from([]);
this.connected = false;
this.timeoutSet = false;
this.connectCallbacks = [];
this.responseCallbacks = {};
this.requestTimeouts = [];
this.errorCallbacks = {};
this.timeoutSet = false;
this.responseBuffer = Buffer.from([]);
if (this._socket) {
this._socket.destroy();
delete this._socket;
Expand Down Expand Up @@ -290,6 +292,8 @@ export class Server extends events.EventEmitter {

close() {
if (this._socket) {
// TODO: this should probably be destroy() in at least some, if not all,
// cases.
this._socket.end();
}
}
Expand Down Expand Up @@ -319,10 +323,6 @@ const timeoutHandler = function (server: Server, sock: net.Socket) {

if (soonestTimeout <= now) {
// timeout occurred!
sock.end();
server.connected = false;
server._socket = undefined;
server.timeoutSet = false;
server.error(new Error("socket timed out waiting on response."));
} else {
// no timeout! Setup next one.
Expand Down

0 comments on commit d7ce226

Please # to comment.