Skip to content

Instantly share code, notes, and snippets.

@wolfeidau
Created October 7, 2013 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfeidau/6875651 to your computer and use it in GitHub Desktop.
Save wolfeidau/6875651 to your computer and use it in GitHub Desktop.
Leaking Code
module.exports = {key: 'XXXX', secret:'XXXX'};
'use strict';
var url = require('url');
var request = require('request');
var creds = require('./creds.js');
var scheme = 'https';
var hostname = 'api.tempo-db.com';
var baseUrl = scheme + '://' + hostname;
var auth = 'Basic ' + new Buffer(creds.key + ':' + creds.secret).toString('base64');
var headers = {
Host: hostname,
Authorization: auth
};
var seriesKey = '1_D90343085872CA9C_687_0_2000';
function uploadEntry(cb){
var data = [];
data.push({t: new Date(), v: Math.random() * 50})
var opts = {
url: url.parse(baseUrl + '/v1/series/key/' + seriesKey + '/data/'),
method: 'POST',
headers: headers,
body: JSON.stringify(data)
}
console.log('sending', data[0]);
request(opts,cb);
};
function callback(err, result){
if (!err) console.log('statusCode', result.statusCode);
}
setInterval(uploadEntry.bind(null, callback), 1000);
@wolfeidau
Copy link
Author

After running for 15 minutes or so.

 18829 markw     172M  172M sleep    1    0   0:00:08 0.3% node/7

From mdb i get.

    24035000c3f1      428       35 Array
     a0b2538c919      429        2 Object: domain, bytes
     a0b25357119      432        4 Object: url, method, headers, body
     a0b2530d829      464        3 Object: sslOutEnd, close, finish
     a0b25329da1      464        4 Object: server, date, content-length, ...
     a0b25331e79      464        8 Array
     a0b25317141      465        5 Object: drain, end, _socketEnd, close, ...
     a0b25326911      470       27 ClientRequest: domain, _events, ...
     a0b25311169      474        6 Object: sslOutEnd, agentRemove, drain, ...
     a0b2530cab1      477        4 Object: end, readable, close, data
     a0b25308789      487        2 Object: readStop, readStart
     a0b2530a039      499       12 Url: protocol, slashes, auth, host, ...
     a0b25311359      515       27 IncomingMessage: _readableState, ...
     a0b25311859      527       21 Socket: _connecting, _handle, ...
     a0b253112b9      531       23 EncryptedStream: _readableState, ...
     a0b25311841      533       40 Request: _maxListeners, domain, method, ...
     a0b25310021      608        3 Object: Host, Authorization, ...
     a0b2530b871      637        1 Credentials: context
    2403500118a1      641        2 Object: domain, oncomplete
     a0b253507d1      649        7 Array
     a0b2530ea51      654       19 SecurePair: domain, _events, ...
     a0b25316b59      768        0 SecureContext
     a0b2530b891      814        0 Connection
     a0b2530ffa9      819        3 Object: authorization, host, ...
    240350004469      854        3 Object: domain, , bytes
     a0b25356f99     1282        1 Arguments: length
     a0b2530d841     1831       16 WritableState: highWaterMark, ...
     a0b2530c9f1     2446       21 ReadableState: highWaterMark, buffer, ...
    133e90535199     2566        4 Array
     a0b2530cae1     3400        0 Object
     a0b2532a1c1     6400        3 Array
     a0b2532a4a9     6484        2 Array
     a0b2530add9     6694        3 Buffer: length, parent, offset
     a0b2532a661     7712        2 Object: callback, domain
     a0b25308841    11417        1 Array
     a0b2530a0b1    12391        0 Array
    21578cfde429    14252        2 Arguments: length, callee

@wolfeidau
Copy link
Author

So with the addition of full gc.

     31c96f17591       26       21 ReadableState: highWaterMark, buffer, ...
     31c96e8d139       27        2 Object: encoding, flag
    10a68790ef21       27        3 Object: name, email, url
     31c96ef20e9       27       15 Array
    10a687912b39       28        2 Object: url, type
     31c96e9f999       30       12 PropertyDescriptor: value_, hasValue_, ...
     31c96e048b1       33        4 NativeModule: filename, id, exports, ...
     31c96e9d181       39        6 Array
     31c96e8d641       44        3 Buffer: length, parent, offset
     31c96ee37c1       45       13 Array
     31c97e8dcd1       47        0
     31c96ee2089       48       14 Array
     31c96e94969       50        8 Array
    10a687912389       52        7 Module: id, exports, parent, filename, ...
     31c96e93d11       54       10 Array
     31c96e954c1       56        9 Array
     31c96e8cd31       56       11 Array
     31c96e9d269       57        7 Array
     31c96e8ca99       59       12 Array
     31c96e8d291       62       13 <anonymous> (as <anon>): dev, mode, ...
     31c96e94921      106        3 Array
     31c96e9c489      113        4 Array
     31c96e9c3b9      113        5 Array
     31c96e8c709      163        2 Arguments: length, callee
     31c96e93dd1      260        1 Array
     31c96e8c791      425        2 Array
     31c96e9a8f9      695        0 Object
     31c96e082f1     1147        0 Array

@wolfeidau
Copy link
Author

pmap output.

[markw@38139342-096a-4f96-9e4d-843d0ca05af4 ~]$ pmap 19493
19493:  node --expose-gc httptest.js
0000000000400000       7012K r-x--  /opt/local/bin/node
0000000000AE8000         28K rw---  /opt/local/bin/node
0000000000AEF000      26008K rw---    [ heap ]
0000031C96000000       8192K rw---    [ anon ]
0000031C96800000       4096K rw---    [ anon ]
0000031C96C00000       2048K rw---    [ anon ]
0000031C96E00000       1024K rw---    [ anon ]
0000031C96F00000       1024K rw---    [ anon ]
0000031C97000000       8192K rw---    [ anon ]
0000031C97800000       4096K rw---    [ anon ]
0000031C97C00000       2048K rw---    [ anon ]
0000031C97E00000       1024K rw---    [ anon ]
0000031C97F00000       1024K rw---    [ anon ]
0000050980900000        148K rw---    [ anon ]
000008A7D8100000        212K rw---    [ anon ]
000009746B100000       1024K rw---    [ anon ]
00000DF5837CE000          4K rw---    [ anon ]
00000DF5837CF000          4K rw---    [ anon ]
00000DF5837D0000          8K rw---    [ anon ]
00000DF5837D2000         16K rw---    [ anon ]
00000DF5837D6000         32K rw---    [ anon ]
00000DF5837DE000         64K rw---    [ anon ]
00000DF5837EE000        128K rw---    [ anon ]
00000DF58380E000        256K rw---    [ anon ]
00000DF58384E000        512K rw---    [ anon ]
00000DF5838CE000       1024K rw---    [ anon ]
000010A687900000       1024K rw---    [ anon ]
00001A4AAAF00000        532K rw---    [ anon ]
00001E41C1300000       1024K rw---    [ anon ]
000021EA63100000       1024K rw---    [ anon ]
0000238194800000         20K rw---    [ anon ]
0000238194806000        996K rwx--    [ anon ]
0000238194900000         20K rw---    [ anon ]
0000238194906000        996K rwx--    [ anon ]
0000238194A00000         20K rw---    [ anon ]
0000238194A06000        996K rwx--    [ anon ]
000023819AD00000         20K rw---    [ anon ]
000023819AD06000        996K rwx--    [ anon ]
000037E12ACC0000        128K rw---    [ anon ]
00003B038B400000        148K rw---    [ anon ]
00003DAE62C00000       1024K rw---    [ anon ]
FFFFFD7FFD7EF000          4K rw--R    [ stack tid=7 ]
FFFFFD7FFD9EE000          4K rw--R    [ stack tid=6 ]
FFFFFD7FFD9F0000          4K r-x--  /lib/amd64/libsendfile.so.1
FFFFFD7FFDA01000          4K rw---  /lib/amd64/libsendfile.so.1
FFFFFD7FFDC2E000          4K rw--R    [ stack tid=5 ]
FFFFFD7FFDC30000       1044K r-x--  /opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64/libstdc++.so.6.0.17
FFFFFD7FFDD44000         40K rw---  /opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64/libstdc++.so.6.0.17
FFFFFD7FFDD4E000         84K rw---  /opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64/libstdc++.so.6.0.17
FFFFFD7FFDD70000       1840K r-x--  /opt/local/lib/libcrypto.so.1.0.0
FFFFFD7FFDF4B000        152K rw---  /opt/local/lib/libcrypto.so.1.0.0
FFFFFD7FFDF71000         12K rw---  /opt/local/lib/libcrypto.so.1.0.0
FFFFFD7FFDFD0000        400K r-x--  /opt/local/lib/libssl.so.1.0.0
FFFFFD7FFE043000         40K rw---  /opt/local/lib/libssl.so.1.0.0
FFFFFD7FFE170000         92K r-x--  /opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64/libgcc_s.so.1
FFFFFD7FFE196000          4K rw---  /opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64/libgcc_s.so.1
FFFFFD7FFE197000          4K rw---  /opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64/libgcc_s.so.1
FFFFFD7FFE57C000          8K rw--R    [ stack tid=4 ]
FFFFFD7FFE57F000          4K r-x--  /lib/amd64/libdl.so.1
FFFFFD7FFE600000          8K r-x--  /lib/amd64/libkstat.so.1
FFFFFD7FFE612000          4K rw---  /lib/amd64/libkstat.so.1
FFFFFD7FFE82E000          4K rw--R    [ stack tid=3 ]
FFFFFD7FFE830000         64K rwx--    [ anon ]
FFFFFD7FFEA3E000          4K rw--R    [ stack tid=2 ]
FFFFFD7FFEA40000         68K r-x--  /lib/amd64/libsocket.so.1
FFFFFD7FFEA61000          4K rw---  /lib/amd64/libsocket.so.1
FFFFFD7FFEACD000         12K r-x--  /lib/amd64/libpthread.so.1
FFFFFD7FFEBC0000          8K r-x--  /lib/amd64/libumem_trampoline.so.1
FFFFFD7FFEBD2000          4K rw---  /lib/amd64/libumem_trampoline.so.1
FFFFFD7FFEBE0000         12K rwx--  /lib/amd64/libumem_trampoline.so.1
FFFFFD7FFEBF0000        476K r-x--  /lib/amd64/libumem.so.1
FFFFFD7FFEC77000        144K rw---  /lib/amd64/libumem.so.1
FFFFFD7FFEC9B000         44K rw---  /lib/amd64/libumem.so.1
FFFFFD7FFED10000        532K r-x--  /lib/amd64/libnsl.so.1
FFFFFD7FFEDA5000         12K rw---  /lib/amd64/libnsl.so.1
FFFFFD7FFEDA8000         32K rw---  /lib/amd64/libnsl.so.1
FFFFFD7FFEEE0000        388K r-x--  /lib/amd64/libm.so.2
FFFFFD7FFEF50000         20K rw---  /lib/amd64/libm.so.2
FFFFFD7FFEFB0000        128K rwx--    [ anon ]
FFFFFD7FFEFE0000         64K rwx--    [ anon ]
FFFFFD7FFF000000          4K r--s-  dev:539,6 ino:703437881
FFFFFD7FFF010000         64K rwx--    [ anon ]
FFFFFD7FFF030000         64K rw---    [ anon ]
FFFFFD7FFF04F000        128K rw---    [ anon ]
FFFFFD7FFF070000          4K r-x--    [ anon ]
FFFFFD7FFF080000          4K r-x--    [ anon ]
FFFFFD7FFF090000          4K r-x--    [ anon ]
FFFFFD7FFF0A0000          4K r-x--    [ anon ]
FFFFFD7FFF0B0000          4K r-x--    [ anon ]
FFFFFD7FFF0C1000          4K rwxs-    [ anon ]
FFFFFD7FFF0D0000         24K rwx--    [ anon ]
FFFFFD7FFF0E0000          4K rwx--    [ anon ]
FFFFFD7FFF0F0000          4K rwx--    [ anon ]
FFFFFD7FFF100000       1476K r-x--  /lib/amd64/libc.so.1
FFFFFD7FFF281000         40K rw---  /lib/amd64/libc.so.1
FFFFFD7FFF28B000         20K rw---  /lib/amd64/libc.so.1
FFFFFD7FFF2A0000          4K rwx--    [ anon ]
FFFFFD7FFF2B0000          4K rwx--    [ anon ]
FFFFFD7FFF2C0000          4K rwx--    [ anon ]
FFFFFD7FFF2D0000          4K rwx--    [ anon ]
FFFFFD7FFF2E0000          4K rwx--    [ anon ]
FFFFFD7FFF2F0000          4K rwx--    [ anon ]
FFFFFD7FFF300000          4K rwx--    [ anon ]
FFFFFD7FFF310000          4K rwx--    [ anon ]
FFFFFD7FFF320000          4K rwx--    [ anon ]
FFFFFD7FFF330000          4K rwx--    [ anon ]
FFFFFD7FFF340000          4K rwx--    [ anon ]
FFFFFD7FFF350000          4K rwx--    [ anon ]
FFFFFD7FFF360000          4K rwx--    [ anon ]
FFFFFD7FFF370000          4K rw---    [ anon ]
FFFFFD7FFF380000          4K rw---    [ anon ]
FFFFFD7FFF390000          4K rwx--    [ anon ]
FFFFFD7FFF398000        328K r-x--  /lib/amd64/ld.so.1
FFFFFD7FFF3FA000         12K rwx--  /lib/amd64/ld.so.1
FFFFFD7FFF3FD000          8K rwx--  /lib/amd64/ld.so.1
FFFFFD7FFFDF5000         44K rw---    [ stack ]
         total        86300K

@wolfeidau
Copy link
Author

Diff of pmap.

$ diff pmap.out.1 pmap.out.2
1c1
< 19493:  node --expose-gc httptest.js

---
> 19493:    node --expose-gc httptest.js
17c17
< 000009746B100000       1024K rw---    [ anon ]

---
> 00000D5428700000       1024K rw---    [ anon ]
38,39c38,40
< 000023819AD00000         20K rw---    [ anon ]
< 000023819AD06000        996K rwx--    [ anon ]

---
> 00002381AED00000         20K rw---    [ anon ]
> 00002381AED06000        996K rwx--    [ anon ]
> 00002A0475000000       1024K rw---    [ anon ]
42d42
< 00003DAE62C00000       1024K rw---    [ anon ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment