Skip to content

Commit 300ea5d

Browse files
committed
Use on-finished instead of override socket destroy
fixes #20
1 parent 0ff71e9 commit 300ea5d

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

HISTORY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
unreleased
22
==========
33

4+
* Use `on-finished` instead of override socket destroy
5+
- Addresses memory leaking on keep alive connections
6+
- Ensures timers always get cleaned up
47
* perf: enable strict mode
58
* perf: remove argument reassignment
69
* perf: use standard option existence check

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(The MIT License)
22

33
Copyright (c) 2014 Jonathan Ong <[email protected]>
4-
Copyright (c) 2014 Douglas Christopher Wilson <[email protected]>
4+
Copyright (c) 2014-2015 Douglas Christopher Wilson <[email protected]>
55

66
Permission is hereby granted, free of charge, to any person obtaining
77
a copy of this software and associated documentation files (the

index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* connect-timeout
33
* Copyright(c) 2014 Jonathan Ong
4-
* Copyright(c) 2014 Douglas Christopher Wilson
4+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
55
* MIT Licensed
66
*/
77

@@ -14,6 +14,7 @@
1414
var createError = require('http-errors');
1515
var debug = require('debug')('connect:timeout');
1616
var ms = require('ms');
17+
var onFinished = require('on-finished');
1718
var onHeaders = require('on-headers');
1819

1920
/**
@@ -37,7 +38,6 @@ module.exports = function timeout(time, options) {
3738
var respond = opts.respond === undefined || opts.respond === true;
3839

3940
return function(req, res, next) {
40-
var destroy = req.socket.destroy;
4141
var id = setTimeout(function(){
4242
req.timedout = true;
4343
req.emit('timeout', delay);
@@ -51,14 +51,13 @@ module.exports = function timeout(time, options) {
5151
clearTimeout(id);
5252
};
5353

54-
req.socket.destroy = function(){
55-
clearTimeout(id);
56-
destroy.call(this);
57-
};
58-
5954
req.timedout = false;
6055

61-
onHeaders(res, function(){
56+
onFinished(res, function () {
57+
clearTimeout(id);
58+
});
59+
60+
onHeaders(res, function () {
6261
clearTimeout(id);
6362
});
6463

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"debug": "~2.2.0",
1313
"http-errors": "~1.3.1",
1414
"ms": "0.7.1",
15+
"on-finished": "~2.3.0",
1516
"on-headers": "~1.0.0"
1617
},
1718
"devDependencies": {

0 commit comments

Comments
 (0)