summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2013-11-19events: do not accept NaN in setMaxListenersFedor Indutny
2013-11-13tls: handle `ssl.start()` errorsFedor Indutny
2013-11-13events: don't call once twiceTim Wood
Emitting an event within a `EventEmitter#once` callback of the same event name will cause subsequent `EventEmitter#once` listeners of the same name to be called multiple times. var emitter = new EventEmitter(); emitter.once('e', function() { emitter.emit('e'); console.log(1); }); emitter.once('e', function() { console.log(2); }); emitter.emit('e'); // Output // 2 // 1 // 2 Fix the issue, by calling the listener method only if it was not already called.
2013-11-11repl: do not insert duplicates into completionsMaciej MaƂecki
Fix invalid `hasOwnProperty` function usage. For example, before in the REPL: ``` > Ar<Tab> Array Array ArrayBuffer ``` Now: ``` > Ar<Tab> Array ArrayBuffer ``` Fixes #6255. Closes #6498.
2013-11-09tls: prevent stalls by using read(0)Fedor Indutny
Do not `.push()` the same data as just passed to `.ondata()`, it may be read by 'data' event listeners. fix #6277
2013-10-25debugger: Fix bug in sb() with unnamed scriptMaxim Bogushevich
setBreakpoint() cause error when unnamed script is loaded
2013-10-16http: provide backpressure for pipeline floodisaacs
If a client sends a lot more pipelined requests than we can handle, then we need to provide backpressure so that the client knows to back off. Do this by pausing both the stream and the parser itself when the responses are not being read by the downstream client. Backport of 085dd30
2013-10-09tls: fix premature connection terminationBen Noordhuis
Destroying the TLS session implies destroying the underlying socket but before this commit, that was done with net.Socket#destroy() rather than net.Socket#destroySoon(). The former closes the connection right away, even when there is still data to write. In other words, sometimes the final TLS record got truncated. Fixes #6107.
2013-10-08fs: fix fs.truncate() file content zeroing bugBen Noordhuis
fs.truncate() and its synchronous sibling are implemented in terms of open() + ftruncate(). Unfortunately, it opened the target file with mode 'w' a.k.a. 'write-only and create or truncate at open'. The subsequent call to ftruncate() then moved the end-of-file pointer from zero to the requested offset with the net result of a file that's neatly truncated at the right offset and filled with zero bytes only. This bug was introduced in commit 168a5557 but in fairness, before that commit fs.truncate() worked like fs.ftruncate() so it seems we've never had a working fs.truncate() until now. Fixes #6233.
2013-09-27tls: fix sporadic hang and partial readsFedor Indutny
Do not decrement size in read loop, its used later, when comparing to `bytesRead`. fix #6270 NOTE: Original patch contributed by @roadrunner2
2013-09-23readline: handle input starting with control charsEric Schrock
Handle control characters only when there is a single byte in the stream, otherwise fall through to the standard multibyte handling.
2013-09-13tls: don't push() incoming data when ondata is setNathan Rajlich
Otherwise the data ends up "on the wire" twice, and switching between consuming the stream using `ondata` vs. `read()` would yield duplicate data, which was bad.
2013-09-09tls: fix setting NPN protocolsFedor Indutny
The NPN protocols was set on `require('tls')` or `global` object instead of being a local property. This fact lead to strange persistence of NPN protocols, and sometimes incorrect protocol selection (when no NPN protocols were passed in client options). fix #6168
2013-09-05stream: objectMode transforms allow falsey valuesisaacs
Closes #6183
2013-08-28stream: check _events before _events.errorisaacs
This fixes the regression introduced by 5458079, which breaks the net/net-pipe benchmark script. Closes #6145
2013-08-27stream: Pass 'buffer' encoding to decoded writablesisaacs
Since the encoding is no longer relevant once it is decoded to a Buffer, it is confusing and incorrect to pass the encoding as 'utf8' or whatever in those cases. Closes #6119
2013-08-21tls: fix assertion when ssl is destroyed at readFedor Indutny
`maybeInitFinished()` can emit the 'secure' event which in turn destroys the connection in case of authentication failure and sets `this.pair.ssl` to `null`. If such condition appeared after non-empty read - loop will continue and `clearOut` will be called on `null` object instead of `crypto::Connection` instance. Resulting in the following assertion: ERROR: Error: Hostname/IP doesn't match certificate's altnames Assertion failed: handle->InternalFieldCount() > 0 fix #5756
2013-08-20fs: use correct self reference for autoClose testGil Pedersen
2013-08-19stream: Throw on 'error' if listeners removedisaacs
In this situation: writable.on('error', handler); readable.pipe(writable); writable.removeListener('error', handler); writable.emit('error', new Error('boom')); there is actually no error handler, but it doesn't throw, because of the fix for stream.once('error', handler), in 23d92ec. Note that simply reverting that change is not valid either, because otherwise this will emit twice, being handled the first time, and then throwing the second: writable.once('error', handler); readable.pipe(writable); writable.emit('error', new Error('boom')); Fix this with a horrible hack to make the stream pipe onerror handler added before any other userland handlers, so that our handler is not affected by adding or removing any userland handlers. Closes #6007.
2013-08-17dgram: fix assertion on bad send() argumentsBen Noordhuis
Add range checks for the offset, length and port arguments to dgram.Socket#send(). Fixes the following assertion: node: ../../src/udp_wrap.cc:264: static v8::Handle<v8::Value> node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion `offset < Buffer::Length(buffer_obj)' failed. And: node: ../../src/udp_wrap.cc:265: static v8::Handle<v8::Value> node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion `length <= Buffer::Length(buffer_obj) - offset' failed. Interestingly enough, a negative port number was accepted until now but silently ignored. (In other words, it would send the datagram to a random port.) This commit exposed a bug in the simple/test-dgram-close test which has also been fixed. This is a back-port of commit 41ec6d0 from the master branch. Fixes #6025.
2013-08-17readline: pause stdin before turning off terminal raw modeDaniel Chatfield
On windows, libuv will immediately make a `ReadConsole` call (in the thread pool) when a 'flowing' `uv_tty_t` handle is switched to line-buffered mode. That causes an immediate issue for some users, since libuv can't cancel the `ReadConsole` operation on Windows 8 / Server 2012 and up if the program switches back to raw mode later. But even if this will be fixed in libuv at some point, it's better to avoid the overhead of starting work in the thread pool and immediately cancelling it afther that. See also f34f1e3, where the same change is made for the opposite flow, e.g. move `resume()` after `_setRawMode(true)`. Fixes #5927 This is a backport of dfb0461 (see #5930) to the v0.10 branch.
2013-08-15http: Handle hex/base64 encodings properlyisaacs
This is a backport of 6d3d60aced39d59eaa5e705b7d822c227d0d3dae for v0.10.
2013-08-06stream: Fix double pipe error emitEran Hammer
If an error listener is added to a stream using once() before it is piped, it is invoked and removed during pipe() but before pipe() sees it which causes it to be emitted again. Fixes #4155 #4978
2013-08-01events: fix memory leak, don't leak event namesBen Noordhuis
Before this commit, events were set to undefined rather than deleted from the EventEmitter's backing dictionary for performance reasons: `delete obj.key` causes a transition of the dictionary's hidden class and that can be costly. Unfortunately, that introduces a memory leak when many events are added and then removed again. The strings containing the event names are never reclaimed by the garbage collector because they remain part of the dictionary. That's why this commit makes EventEmitter delete events again. This effectively reverts commit 0397223. Fixes #5970.
2013-07-31http: improve chunked res.write(buf) performanceBen Noordhuis
Avoid a costly buffer-to-string operation. Instead, allocate a new buffer, copy the chunk header and data into it and send that. The speed difference is negligible on small payloads but it really shines with larger (10+ kB) chunks. benchmark/http/end-vs-write-end with 64 kB chunks gives 45-50% higher throughput. With 1 MB chunks, the difference is a staggering 590%. Of course, YMMV will vary with real workloads and networks but this commit should have a positive impact on CPU and memory consumption. Big kudos to Wyatt Preul (@wpreul) for reporting the issue and providing the initial patch. Fixes #5941 and #5944.
2013-07-17url: Fix edge-case when protocol is non-lowercaseShuan Wang
When using url.parse(), path and pathname usually return '/' when there is no path available. However when you have a protocol that contains non-lowercase letters and the input string does not have a trailing slash, both path and pathname will be undefined.
2013-07-14tls: Trivial use_strict fixisaacs
2013-07-09tls: only wait for finish if we haven't seen itTimothy J Fontaine
A pooled https agent may get a Connection: close, but never finish destroying the socket as the prior request had already emitted finish likely from a pipe. Since the socket is not marked as destroyed it may get reused by the agent pool and result in an ECONNRESET. re: #5712 #5739
2013-07-08http: Dump response when request is abortedisaacs
Fixes #5695
2013-07-01http: use an unref'd timer to fix delay in exitPeter Rust
There was previously up to a second exit delay when exiting node right after an http request/response, due to the utcDate() function doing a setTimeout to update the cached date/time. Fixing this should increase the performance of our http tests.
2013-07-01zlib: allow zero values for level and strategyBrian White
This is a back-port of commit c9644fb from the master branch.
2013-06-27buffer: add comment explaining buffer alignmentBen Noordhuis
Avoids alignment issues (unaligned loads/stores) on ARM. Originally added in commit 285d8c6. Fixes #3030.
2013-06-17readline: make `ctrl + L` clear the screenYuan Chuan
2013-06-16net: Do not destroy socket mid-writeisaacs
The fix in e0519ace315c7ce14278d5eaab8d1d72a0a0a054 is overly zealous, and can destroy a socket while there are still outstanding writes in progress. Closes GH-5688
2013-06-12Revert "http: remove bodyHead from 'upgrade' events"isaacs
This reverts commit a40133d10cdb911b27fe8d46d67a835b0103bbf1. Unfortunately, this breaks socket.io. Even though it's not strictly an API change, it is too subtle and in too brittle an area of node, to be done in a stable branch. Conflicts: doc/api/http.markdown
2013-06-11crypto: fix utf8/utf-8 encoding checkBen Noordhuis
Normalize the encoding in getEncoding() before using it. Fixes a "AssertionError: Cannot change encoding" exception when the caller mixes "utf8" and "utf-8". Fixes #5655.
2013-06-05net: Destroy when not readable and not writableisaacs
This is only relevant for CentOS 6.3 using kernel version 2.6.32. On other linuxes and darwin, the `read` call gets an ECONNRESET in that case. On sunos, the `write` call fails with EPIPE. However, old CentOS will occasionally send an EOF instead of a ECONNRESET or EPIPE when the client has been destroyed abruptly. Make sure we don't keep trying to write or read more in that case. Fixes #5504 However, there is still the question of what libuv should do when it gets an EOF. Apparently in this case, it will continue trying to read, which is almost certainly the wrong thing to do. That should be fixed in libuv, even though this works around the issue.
2013-06-04url: remove unused global variableBen Noordhuis
2013-06-03url: Set href to null by defaultisaacs
2013-06-03url: Properly parse certain oddly formed urlsisaacs
In cases where there are multiple @-chars in a url, Node currently parses the hostname and auth sections differently than web browsers. This part of the bug is serious, and should be landed in v0.10, and also ported to v0.8, and releases made as soon as possible. The less serious issue is that there are many other sorts of malformed urls which Node either accepts when it should reject, or interprets differently than web browsers. For example, `http://a.com*foo` is interpreted by Node like `http://a.com/*foo` when web browsers treat this as `http://a.com%3Bfoo/`. In general, *only* the `hostEndingChars` should be the characters that delimit the host portion of the URL. Most of the current `nonHostChars` that appear in the hostname should be escaped, but some of them (such as `;` and `%` when it does not introduce a hex pair) should raise an error. We need to have a broader discussion about whether it's best to throw in these cases, and potentially break extant programs, or return an object that has every field set to `null` so that any attempt to read the hostname/auth/etc. will appear to be empty.
2013-06-03stream: unshift('') is a noopisaacs
In some cases, the http CONNECT/Upgrade API is unshifting an empty bodyHead buffer onto the socket. Normally, stream.unshift(chunk) does not set state.reading=false. However, this check was not being done for the case when the chunk was empty (either `''` or `Buffer(0)`), and as a result, it was causing the socket to think that a read had completed, and to stop providing data. This bug is not limited to http or web sockets, but rather would affect any parser that unshifts data back onto the source stream without being very careful to never unshift an empty chunk. Since the intent of unshift is to *not* change the state.reading property, this is a bug. Fixes #5557 Fixes LearnBoost/socket.io#1242
2013-05-30repl: fix JSON.parse error checkBrian White
Before this, entering something like: > JSON.parse('066'); resulted in the "..." prompt instead of displaying the expected "SyntaxError: Unexpected number"
2013-05-30tls: proper .destroySoonFedor Indutny
1. Emit `sslOutEnd` only when `_internallyPendingBytes() === 0`. 2. Read before checking `._halfRead`, otherwise we'll see only previous value, and will invoke `._write` callback improperly. 3. Wait for both `end` and `finish` events in `.destroySoon`. 4. Unpipe encrypted stream from socket to prevent write after destroy.
2013-05-28tls: invoke write cb only after opposite read endFedor Indutny
Stream's `._write()` callback should be invoked only after it's opposite stream has finished processing incoming data, otherwise `finish` event fires too early and connection might be closed while there's some data to send to the client. see #5544
2013-05-28tls: ignore .shutdown() syscall errorFedor Indutny
Quote from SSL_shutdown man page: The output of SSL_get_error(3) may be misleading, as an erroneous SSL_ERROR_SYSCALL may be flagged even though no error occurred. Also, handle all other errors to prevent assertion in `ClearError()`.
2013-05-24tls: retry writing after hello parse errorFedor Indutny
When writing bad data to EncryptedStream it'll first get to the ClientHello parser, and, only after it will refuse it, to the OpenSSL. But ClientHello parser has limited buffer and therefore write could return `bytes_written` < `incoming_bytes`, which is not the case when working with OpenSSL. After such errors ClientHello parser disables itself and will pass-through all data to the OpenSSL. So just trying to write data one more time will throw the rest into OpenSSL and let it handle it.
2013-05-24http: remove bodyHead from 'upgrade' eventsNathan Zadoks
Streams2 makes this unnecessary. An empty buffer is provided for compatibility.
2013-05-23http: Return true on empty writes, not falseisaacs
Otherwise, writing an empty string causes the whole program to grind to a halt when piping data into http messages. This wasn't as much of a problem (though it WAS a bug) in 0.8 and before, because our hyperactive 'drain' behavior would mean that some *previous* write() would probably have a pending drain event, and cause things to start moving again.
2013-05-23http: save roundtrips, convert buffers to stringsBen Noordhuis
This commit adds an optimization to the HTTP client that makes it possible to: * Pack the headers and the first chunk of the request body into a single write(). * Pack the chunk header and the chunk itself into a single write(). Because only one write() system call is issued instead of several, the chances of data ending up in a single TCP packet are phenomenally higher: the benchmark with `type=buf size=32` jumps from 50 req/s to 7,500 req/s, a 150-fold increase. This commit removes the check from e4b716ef that pushes binary encoded strings into the slow path. The commit log mentions that: We were assuming that any string can be concatenated safely to CRLF. However, for hex, base64, or binary encoded writes, this is not the case, and results in sending the incorrect response. For hex and base64 strings that's certainly true but binary strings are 'das Ding an sich': string.length is the same before and after decoding. Fixes #5528.
2013-05-21net: use timers._unrefActive for internal timeoutsTimothy J Fontaine