0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
Commit Graph

2433 Commits

Author SHA1 Message Date
isaacs
22c7d134e2 lint 2013-04-11 11:06:20 -07:00
Ben Noordhuis
212eb8a52e child_process: fix O(n*m) scan of cmd string
Don't scan the whole string for a "NODE_" substring, just check that
the string starts with the expected prefix.

This is a reprise of dbbfbe7 but this time for the child_process
module.
2013-04-11 13:53:18 +02:00
Ben Noordhuis
dbbfbe74ca cluster: fix O(n*m) scan of cmd string
Don't scan the whole string for a "NODE_CLUSTER_" substring, just check
that the string starts with the expected prefix. The linear scan was
causing a noticeable (but unsurprising) slowdown on messages with a
large .cmd string property.
2013-04-11 13:42:34 +02:00
Fedor Indutny
c665b8e9ba net: fix socket.bytesWritten Buffers support
Buffer.byteLength() works only for string inputs. Thus, when connection
has pending Buffer to write, it should just use it's length instead of
throwing exception.
2013-04-10 14:51:10 +04:00
Łukasz Walukiewicz
2e28832660 buffer: fix offset checks
Fixed offset checks in Buffer.readInt32LE() and Buffer.readInt32BE()
functions.
2013-04-08 16:17:38 -07:00
isaacs
c93af860a0 stream: call write cb before finish event
Since 049903e, an end callback could be called before a write
callback if end() is called before the write is done. This patch
resolves the issue.

In collaboration with @gne

Fixes felixge/node-formidable#209
Fixes #5215
2013-04-09 02:09:51 +04:00
isaacs
e4b716efaa http: Support write(data, 'hex')
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.

An unusual edge case, but certainly a bug.
2013-04-08 09:33:56 -07:00
Andreas Madsen
fed8cff1d0 crypto: fix constructor call in crypto streams
When using some stream method on a lazy crypto stream, the transform
constructor wasn't called. This caused the internal state object to
be undefined.
2013-04-08 14:45:42 +04:00
Fedor Indutny
ff32ecd5bf net: account encoding in .byteLength 2013-04-08 11:48:46 +04:00
Fedor Indutny
eb39c9854a net: fix buffer iteration in bytesWritten 2013-04-08 01:17:40 +04:00
Tobias Müllerleile
4108c31293 tls: Re-enable check of CN-ID in cert verification
RFC 6125 explicitly states that a client "MUST NOT seek a match
for a reference identifier of CN-ID if the presented identifiers
include a DNS-ID, SRV-ID, URI-ID, or any application-specific
identifier types supported by the client", but it MAY do so if
none of the mentioned identifier types (but others) are present.
2013-04-07 22:09:57 +04:00
Rafael Garcia
bd0d45818e stream: unused variable 2013-04-05 12:05:58 -07:00
Rafael Garcia
ea4f0b4a6b stream: remove vestiges of previous _transform API 2013-04-05 12:05:58 -07:00
isaacs
88686aa410 http: Remove legacy ECONNRESET workaround code
Fix #5179
2013-04-03 10:18:42 -07:00
Fedor Indutny
5902bc45c5 child_process: acknowledge sent handles
Fix race-condition when multiple handles are sent and SCM_RIGHTS
messages are gets merged by OS by avoiding sending multiple handles at
once!

fix #4885
2013-04-03 09:56:48 -07:00
isaacs
4716dc662d assert: Simplify AssertError creation 2013-04-03 09:52:56 -07:00
isaacs
234fb122bb http client: Ensure socket cleanup on response end
If an http response has an 'end' handler that throws, then the socket
will never be released back into the pool.

Granted, we do NOT guarantee that throwing will never have adverse
effects on Node internal state.  Such a guarantee cannot be reasonably
made in a shared-global mutable-state side-effecty language like
JavaScript.  However, in this case, it's a rather trivial patch to
increase our resilience a little bit, so it seems like a win.

There is no semantic change in this case, except that some event
listeners are removed, and the `'free'` event is emitted on nextTick, so
that you can schedule another request which will re-use the same socket.
From the user's point of view, there should be no detectable difference.

Closes #5107
2013-04-02 20:34:08 +04:00
isaacs
164d5b3465 tls: Destroy socket when encrypted side closes
The v0.8 Stream.pipe() method automatically destroyed the destination
stream whenever the src stream closed.  However, this caused a lot of
problems, and was removed by popular demand.  (Many userland modules
still have a no-op destroy() method just because of this.) It was also
very hazardous because this would be done even if { end: false } was
passed in the pipe options.

In v0.10, we decided that the 'close' event and destroy() method are
application-specific, and pipe() doesn't automatically call destroy().
However, TLS actually depended (silently) on this behavior.  So, in this
case, we should just go ahead and destroy the thing when close happens.

Closes #5145
2013-04-01 10:53:49 -07:00
Mitar
e5b90a14b8 querystring: Removing unnecessary binding
Binding of `http_parser` in querystring isn't used anywhere and should
be removed.
2013-04-01 14:30:34 +04:00
Nathan Rajlich
55ea7ccf70 repl: use more readable RegExp syntax for spaces
This is just a cosmetic change really, nothing major.
2013-03-30 13:35:36 -07:00
Nathan Rajlich
085f9d636b repl: isSyntaxError() catches "strict mode" errors
Closes #5178.
2013-03-30 13:10:30 -07:00
isaacs
7af075ee30 crypto: Pass options to ctor calls 2013-03-29 09:39:51 -07:00
Fedor Indutny
4580be0882 tls: handle SSL_ERROR_ZERO_RETURN
see #5004
2013-03-28 21:59:19 +04:00
wicked
39058bef07 setTimeout: do not calculate Timeout._when property
Dramatically improves Timer performance.
2013-03-28 10:40:15 -07:00
isaacs
929e4d9c9a stream: Emit readable on ended streams via read(0)
cc: @mjijackson
2013-03-28 10:27:18 -07:00
isaacs
eafa902632 stream: Handle late 'readable' event listeners
In cases where a stream may have data added to the read queue before the
user adds a 'readable' event, there is never any indication that it's
time to start reading.

True, there's already data there, which the user would get if they
checked However, as we use 'readable' event listening as the signal to
start the flow of data with a read(0) call internally, we ought to
trigger the same effect (ie, emitting a 'readable' event) even if the
'readable' listener is added after the first emission.

To avoid confusing weirdness, only the *first* 'readable' event listener
is granted this privileged status.  After we've started the flow (or,
alerted the consumer that the flow has started) we don't need to start
it again.  At that point, it's the consumer's responsibility to consume
the stream.

Closes #5141
2013-03-28 10:27:18 -07:00
Fedor Indutny
ae86fa84fe tls: handle errors before calling C++ methods
Calling `this.pair.encrypted._internallyPendingBytes()` before
handling/resetting error will result in assertion failure:

../src/node_crypto.cc:962: void node::crypto::Connection::ClearError():
Assertion `handle_->Get(String::New("error"))->BooleanValue() == false'
failed.

see #5058
2013-03-27 16:26:24 +04:00
Trevor Norris
f0b68892d4 domain: fix domain callback from MakeCallback
Since _tickCallback and _tickDomainCallback were both called from
MakeCallback, it was possible for a callback to be called that required
a domain directly to _tickCallback.

The fix was to implement process.usingDomains(). This will set all
applicable functions to their domain counterparts, and set a flag in cc
to let MakeCallback know domain callbacks always need to be checked.

Added test in own file. It's important that the test remains isolated.
2013-03-26 21:26:17 -07:00
Ben Noordhuis
9352c19885 child_process: don't emit same handle twice
It's possible to read multiple messages off the parent/child channel.
When that happens, make sure that recvHandle is cleared after emitting
the first message so it doesn't get emitted twice.
2013-03-25 23:07:30 +01:00
Ben Noordhuis
cfd0dca9ae crypto: make getCiphers() return non-SSL ciphers
Commit f53441a added crypto.getCiphers() as a function that returns the
names of SSL ciphers.

Commit 14a6c4e then added crypto.getHashes(), which returns the names of
digest algorithms, but that creates a subtle inconsistency: the return
values of crypto.getHashes() are valid arguments to crypto.createHash()
but that is not true for crypto.getCiphers() - the returned values are
only valid for SSL/TLS functions.

Rectify that by adding tls.getCiphers() and making crypto.getCiphers()
return proper cipher names.
2013-03-25 18:42:07 +01:00
Ben Noordhuis
44843a6062 child_process: fix sending utf-8 to child process
In process#send() and child_process.ChildProcess#send(), use 'utf8' as
the encoding instead of 'ascii' because 'ascii' mutilates non-ASCII
input. Correctly handle partial character sequences by introducing
a StringDecoder.

Sending over UTF-8 no longer works in v0.10 because the high bit of
each byte is now cleared when converting a Buffer to ASCII. See
commit 96a314b for details.

Fixes #4999 and #5011.
2013-03-25 13:23:17 +01:00
isaacs
c0d500102a stream: Fix early end in Writables on zero-length writes
Doing this causes problems:

    z.write(Buffer(0));
    z.end();

Fix by not ending Writable streams while they're still in the process of
writing something.
2013-03-24 14:23:21 -07:00
Alexey Kupershtokh
9fae4dc102 timer: fix off-by-one ms error
Fix #5103
2013-03-23 18:46:14 -07:00
Gil Pedersen
c3aae9cf95 stream: Fix stall in Transform under very specific conditions
The stall is exposed in the test, though the test itself asserts before
it stalls.

The test is constructed to replicate the stalling state of a complex
Passthrough usecase since I was not able to reliable trigger the stall.

Some of the preconditions for triggering the stall are:
  * rs.length >= rs.highWaterMark
  * !rs.needReadable
  * _transform() handler that can return empty transforms
  * multiple sync write() calls

Combined this can trigger a case where rs.reading is not cleared when
further progress requires this. The fix is to always clear rs.reading.
2013-03-21 17:49:12 -07:00
Fedor Indutny
bfd16de125 timers: handle signed int32 overflow in enroll()
Before this patch calling `socket.setTimeout(0xffffffff)` will result in
signed int32 overflow in C++ which resulted in assertion error:

    Assertion failed: (timeout >= -1), function uv__io_poll, file
    ../deps/uv/src/unix/kqueue.c, line 121.

see #5101
2013-03-21 22:09:05 +04:00
Fedor Indutny
855caa82aa crypto: initialize transform lazily 2013-03-20 16:49:08 -07:00
isaacs
008ab12b7f tls: Prevent hang in readStart
This is not a great fix, and it's a bug that's very tricky to reproduce.

Occasionally, while downloading a file, especially on Linux for some
reason, the pause/resume timing will be just right such that the
CryptoStream is in a 'reading' state, but actually has no data, so it
ought to pull more in.  Because there's no reads happening, it just sits
there, and the process will exit

This is, fundamentally, a factor of how the HTTP implementation sits
atop CryptoStreams and TCP Socket objects, which is utterly horrible,
and needs to be rewritten.  However, in the meantime, npm downloads are
prematurely exiting, causing hard-to-debug "cb() never called!" errors.
2013-03-20 16:14:39 -07:00
Fedor Indutny
34e22b8ee7 tls: always reset this.ssl.error after handling
Otherwise assertion may happen:

    src/node_crypto.cc:962: void node::crypto::Connection::ClearError():
    Assertion `handle_->Get(String::New("error"))->BooleanValue() == false'
    failed.

See #5058
2013-03-20 17:58:01 +04:00
Raymond Feng
25eaacad9a fs: make write/appendFileSync correctly set file mode 2013-03-20 01:37:43 +01:00
Fedor Indutny
b5ddc0cf96 tls: write pending data of opposite side
Fix stucked CryptoStream behaviour, happening when one of the sides
locks-up in queued state.

fix #5023
2013-03-17 20:19:09 +04:00
isaacs
14947b6c5e stream: Return self from readable.wrap
Also, set paused=false *before* calling resume().  Otherwise,
there's an edge case where an immediately-emitted chunk might make
it call pause() again incorrectly.
2013-03-14 16:43:19 -07:00
Gil Pedersen
e8f80bf479 stream: Never call decoder.end() multiple times
Updated version that does what it says without assigning state.decoder.
2013-03-14 16:13:10 -07:00
isaacs
d62cf59dc1 http: Don't hot-path end() for large buffers
The benefits of the hot-path optimization below start to fall off when
the buffer size gets up near 128KB, because the cost of the copy is more
than the cost of the extra write() call.  Switch to the write/end method
at that point.

Heuristics and magic numbers are awful, but slow http responses are
worse.

Fix #4975
2013-03-14 08:04:59 -07:00
Ben Noordhuis
ca5022b8f1 net: improve arbitrary tcp socket support
Consider this example:

  // fd 3 is a bound tcp socket
  var s = net.createServer(cb);
  s.listen({ fd: 3 });
  console.log(s.address());  // prints null

This commit makes net.Server#address() print the actual address.

Ditto for non-listen sockets; properties like net.Socket#localAddress
and net.Socket#remoteAddress now return the correct value.

Fixes #5009.
2013-03-14 15:55:30 +01:00
Ben Noordhuis
e99dff4617 deps: upgrade libuv to 7b66ea1 2013-03-14 15:55:26 +01:00
isaacs
6399839c39 Revert "stream: Never call decoder.end() multiple times"
This reverts commit 615d809ac6.
2013-03-13 15:48:56 -07:00
isaacs
6bd8b7e540 fs: Missing cb errors are deprecated, not a throw
Commit a804347 makes fs function rethrow errors when the callback is
omitted. While the right thing to do, it's a change from the old v0.8
behavior where such errors were silently ignored.

To give users time to upgrade, temporarily disable that and replace it
with a function that warns once about the deprecated behavior.

Close #5005
2013-03-13 15:34:18 -07:00
Gil Pedersen
615d809ac6 stream: Never call decoder.end() multiple times
Fixes decoder.end() being called on every push(null). As the tls module
does this, corrupt stream data could potentially be added to the end.
2013-03-13 15:20:13 -07:00
Fedor Indutny
8135ac1b7f net: handle 'finish' event only after 'connect' 2013-03-13 10:27:23 -07:00
isaacs
327b6e3e1d stream: Don't emit 'end' unless read() called
This solves the problem of calling `readable.pipe(writable)` after the
readable stream has already emitted 'end', as often is the case when
writing simple HTTP proxies.

The spirit of streams2 is that things will work properly, even if you
don't set them up right away on the first tick.

This approach breaks down, however, because pipe()ing from an ended
readable will just do nothing.  No more data will ever arrive, and the
writable will hang open forever never being ended.

However, that does not solve the case of adding a `on('end')` listener
after the stream has received the EOF chunk, if it was the first chunk
received (and thus, length was 0, and 'end' got emitted).  So, with
this, we defer the 'end' event emission until the read() function is
called.

Also, in pipe(), if the source has emitted 'end' already, we call the
cleanup/onend function on nextTick.  Piping from an already-ended stream
is thus the same as piping from a stream that is in the process of
ending.

Updates many tests that were relying on 'end' coming immediately, even
though they never read() from the req.

Fix #4942
2013-03-10 11:08:22 -07:00