Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Destroy() socket on timeout #22

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
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
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
Loading