Commit Graph

3411 Commits

Author SHA1 Message Date
Carsten Varming cb071910ba Use the Runnable.run method to clean direct byte buffers if avaiable.
Motivation:

In JDK9 the Cleaner.clean method cannot be called as it is not exported
from `java.base`. `Runnable.run` should be called instead.

Modifications:
Pick Runnable.run if the cleaner implements Runnable. Otherwise try the
clean method on the class implementing the cleaner.

Result:
The cleaner for direct byte buffers is run on JDK9 as well as earlier
JDKs.
2016-07-20 07:53:30 +02:00
Norman Maurer f04ff5b715 [maven-release-plugin] prepare for next development iteration 2016-06-29 14:41:53 +02:00
Norman Maurer 5f56a03bcb [maven-release-plugin] prepare release netty-3.10.6.Final 2016-06-29 14:41:47 +02:00
Guido Medina 38e048c33f Fixes #5054: IpV4Subnet.contains() always returns true for single-address subnets.
Motivation:
See #5054 and to fix remaining issue stopping Netty 3.10.6.Final being released.

Modification:
Copied IpToInt from Netty 4 and contains() functions.

Result:
Now issue #5054 shown examples are doing what they are expected to do.
2016-06-27 13:27:07 +02:00
Guido Medina c9f963dc8e Removed old JSR 166 CHM which was ported from JDK 5 to JDK 1.4
Motivation:

To benefit from newer JDK CHM as the current internal CHM is the one from JDK 5.

Modification:

Removed old JDK 5 CHM from internal package.

Result:

If you are using JDK 7 or 8 there will be a slight performance benefit.
2016-03-07 15:15:14 +00:00
Hugues Bruant 6baa592772 Fix race when changing channel writability
Motivation:

A rare issue was seen wherein a channel would become
persistently unwritable, even though the underlying
connection was working fine, as evidenced by the fact
that heartbeats were still being received from the
other side.

Examination of WriteRequestQueue and the threading
model around it revealed the following race:

T1: offer MessageEvent
    go over high water mark
    context switch before calling setUnwritable()

T2: poll multiple MessageEvent
    go under low water mark
    call setWritable()

T1: call setUnwritable()

At which point the channel is incorrectly marked as
unwritable and will remain so until another back-and-forth
across the low water mark, which may never happen if
the application uses writability to apply backpressure
on the writer.

The commit log shows that this issue has been present
since commit 2127c8eafe
i.e. version 3.10, when the introduction of user-defined
writability decoupled isWritable from the bufferSize.

Solution:

The use of a mutex was decided against due to the serious
performance implications.

To avoid subtle breakage in backward-compat, deferring the
call to setUnwritable() in the io thread was also decided
against.

Instead, the buffer size is re-checked against the water
mark immediately before firing the interestChanged event
and the writability change is rolled back if necessary.

In addition, a stronger invariant is enforced on poll()
to make it easier to reason about the possible water
mark/writability transitions. This requires minor changes
to NioChannelTest which manually calls poll().
2016-01-29 08:51:40 +01:00
Hugues Bruant a1801ac5b2 SslHandler: Avoid unchecked exception on write
Motivation
----------

Channels.write() is advertised to be thread-safe, however
if one thread starts a write and another closes the channel,
the first thread can find itself with a closed SSLEngine.

Throwing an unchecked exception will cause most programs to
crash, which is not acceptable for such an inconsequential
race.

Solution
--------

Throw SSLException or ClosedChannelException instead, which
are checked exceptions and should therefore be handled in a
non-crashy fashion by most applications.
2016-01-29 08:50:47 +01:00
Norman Maurer bed84dde7a [maven-release-plugin] prepare for next development iteration 2015-10-13 12:09:11 +02:00
Norman Maurer 97523c38ae [maven-release-plugin] prepare release netty-3.10.5.Final 2015-10-13 12:09:01 +02:00
Jens Kordowski de16cfe353 SslHandler misses to store all queued MessageEvents on channel closed
Motivation:

Discovered during static code analysis. Found entries are overwritten
due to error in list instantiation. Also avoiding a possible NPE.

Modification:

Instantiating the list of ChannelFutures if it is not instantiated yet,
instead of overwriting an existing list.

Result:

SslHandler store all queued MessageEvents on channel closed. Fix for
https://github.com/netty/netty/issues/4296
2015-09-30 18:06:47 +02:00
Norman Maurer 9b2e1dca3c [maven-release-plugin] prepare for next development iteration 2015-06-30 15:16:36 +02:00
Norman Maurer c74fe08300 [maven-release-plugin] prepare release netty-3.10.4.Final 2015-06-30 15:16:30 +02:00
atellwu f93f32712e This is a fair-mode alternative of OrderedMemoryAwareThreadPoolExecutor.
Motivation:

1. Unfair of OrderedMemoryAwareThreadPoolExecutor
 The task executed in OrderedMemoryAwareThreadPoolExecutor is unfair in
some situations.
 For example, let's say there is only one executor thread that handle
the events from the two channels, and events are submitted in sequence:

    Channel A (Event A1) , Channel B (Event B), Channel A (Event
A2) , ... , Channel A (Event An)

  Then the events maybe executed in this unfair order:

    -------------------> Timeline --------------------->
    Channel A (Event A1) , Channel A (Event A2) , ... , Channel A (Event
An), Channel B (Event B)

  As we see above, Channel B (Event B) maybe executed unfairly late.
  Even more, if there are too much events come in Channel A, and
one-by-one closely, then Channel B (Event B) would be waiting for a long
while and become "hungry".

Modifications:

1. Fair of FairOrderedMemoryAwareThreadPoolExecutor
 In the same case above ( one executor thread and two channels ) , this
implement will guarantee execution order as:

    -------------------> Timeline -------------------->
    Channel A (Event A1) , Channel B (Event B), Channel A (Event A2) ,
... ,Channel A (Event An)

NOTE: For convenience the case above use one single executor thread, but
the fair mechanism is suitable for multiple executor threads situations.

Result:

There is a fair-mode alternative of OrderedMemoryAwareThreadPoolExecutor
and OrderedDownstreamThreadPoolExecutor now.
2015-06-30 13:35:23 +02:00
Brad Kim 3027a31458 Fix invalid check arguments in 'OpenSslServerContext.setTicketKeys'
Motivation:

Invalid checking arguments causes the function not to work.

Modifications:

Modified checking arguments.

Result:

Fixes #3922
2015-06-29 21:15:58 +02:00
James Roper 46b2eff757 Fix cookie encoding when maxAge is greater than 24 days 2015-05-12 11:23:56 +02:00
Frederic Bregier 7d1a67a375 Proposal to fix issue #3768 (3.10)
Motivations:
When using HttpPostRequestEncoder and trying to set an attribute if a
charset is defined, currenlty implicit Charset.toStrng() is used, given
wrong format.
As in Android for UTF-16 = "com.ibm.icu4jni.charset.CharsetICU[UTF-16]".

Modifications:
Each time charset is used to be printed as its name, charset.name() is
used to get the canonical name.

Result:
Now get "UTF-16" instead.
(3.10 version)
2015-05-11 06:00:53 +02:00
Norman Maurer 3bc72ec377 [maven-release-plugin] prepare for next development iteration 2015-05-08 17:28:12 +02:00
Norman Maurer ad29ba95f5 [maven-release-plugin] prepare release netty-3.10.3.Final 2015-05-08 17:28:07 +02:00
James Roper 2caa38a279 Fix binary compatibility
Change type of Cookie.maxAge back to int to maintain binary
compatibility for drop in fixes.
2015-05-08 17:24:34 +02:00
Norman Maurer 60f0effb08 [maven-release-plugin] prepare for next development iteration 2015-05-08 10:34:21 +02:00
Norman Maurer db0375fd3b [maven-release-plugin] prepare release netty-3.10.2.Final 2015-05-08 10:34:16 +02:00
Stephane Landelle 402edce586 Validate cookie name and value characters
Motivation:

RFC6265 specifies which characters are allowed in a cookie name and value.

Netty is currently too lax, which can used for HttpOnly escaping.

Modification:

Backport new RFC6265 compliant Cookie parsers in cookie subpackage.
Deprecate old Cookie encoders and decoders that will be dropped in 5.0.

Result:

The problem described in the motivation section is fixed.
2015-05-08 09:46:53 +02:00
Hugues Bruant 0e06a53890 Fix overzealous assertion in SslHandler.decode
Motivation:

This AE was seen in the wild at a non-negligible rate among AeroFS
clients (JDK 8, TLS 1.2, mutual auth with RSA certs).

Upon examination of SslHandler's code a few things became apparent:

- the AE is unnecessary given the contract of decode()
- the AE was introduced between 3.8 and 3.9
- the AE is no longer present in in 4.x and master
- branches that do not have the AE skip all the bytes being fed to
  unwrap()

It is not entirely clear what sequence of SSL records can trip the
assert but it seems to happen before the handshake is completed. The
little detailed data we've been able to gather shows the assert being
triggered when

- SSLEngine.unwrap returns NEED_WRAP
- the remaining buffer is a TLS heartbeat record

Likewise, it is not entirely clear if skipping the remaining bytes is
the right thing to do or if they should be fed back to unwrap.

Modifications:

Mirror behavior in newer versions by removing the assert and skipping
bytes fed to unwrap()

Add logging in an effort to get a better understanding of this corner
case.

Result:

Avoid crashes
2015-04-15 15:38:23 +09:00
Trustin Lee 53631bb62c Do not decode a cookie value with mismatching quotes
Motivation:

The following cookie key-value pair should not be decoded:

   a='b;c=d

.. because it is invalid.  Currently, a missing closing quote will make
the CookieDecoder decode "'b;c=d" as a value.  This can be a problem
when 'c=d' is something you don't want to expose.

Modification:

Discard the cookie key-value pair when it has no matching quote.

Result:

The problem described in the motiviation section is fixed.
2015-04-10 11:41:05 +09:00
Hugues Bruant 452df0454d Always fire interestChanged from IO thread
Motivation:

The documented thread model stipulates that all
upstream events should be fired from the IO thread,
which is crucial to avoid race conditions.

See #3546

Modifications:

Change AbstractNioChannel.WriteQueue to check if
the current thread is the IO thread of the worker
and call fireInterestChangedLater accordingly.

Result:

interestChanged event is always fired from IO
thread of channel thus honoring the documented
thread model and fixing race conditions.
2015-03-31 07:31:52 +02:00
Norman Maurer 2f4693d188 [maven-release-plugin] prepare for next development iteration 2015-03-23 19:45:50 +01:00
Norman Maurer 56af5d5f1c [maven-release-plugin] prepare release netty-3.10.1.Final 2015-03-23 19:45:44 +01:00
Neuman Vong 2828eab1e8 Safely encode Strings to ASCII
Motivation:

The current implementation of the encoder writes each character of the
String as a single byte to the buffer, however not all characters are
mappable to a single byte.

Modifications:

If a character is outside the ASCII range, it's converted to '?'.

Result:

A safer encoder for String to ASCII, which substitutes unmappable
characters with'?'.
2015-03-18 15:50:09 +09:00
Trustin Lee faf1d90ae7 Hide password in exception messages of SocksAuthRequest
Related: #3504

Motivation:

There are two places in the SocksAuthRequest constructor where an
IllegalArgumentException is thrown with a password as part of the
exception message.

This constitutes mishandling of confidential information, which can
compromise user privacy and is flagged as critical by security scanners.

Modifications:

Mask the password in the exception messages

Result:

No unexpected password leak
2015-03-17 17:21:30 +09:00
Taeho Kim add0a0c9a4 Accept ';' in the filename of HTTP Content-Disposition header
Motivation:

HttpPostMultipartRequestDecoder threw an ArrayIndexOutOfBoundsException when
trying to decode Content-Disposition header with filename containing ';'.
See issue #3326.

Modifications:

Added splitMultipartHeaderValues method which cares about quotes, and use it in
splitMultipartHeader method, instead of StringUtils.split.

Result:

Filenames can contain semicolons.
2015-01-15 08:26:54 +01:00
Trustin Lee 24ab3b2fd3 Clean-up 2014-12-29 16:02:04 +09:00
Trustin Lee 5f5b63528a [maven-release-plugin] prepare for next development iteration 2014-12-17 13:56:15 +09:00
Trustin Lee 432fdbfd5d [maven-release-plugin] prepare release netty-3.10.0.Final 2014-12-17 13:56:07 +09:00
Frederic Bregier 2127c8eafe Introduce user-defined writability to fix traffic shaping accuracy and efficiency
Motivation:

Several issues were shown by various ticket (#2900 #2956).
Also propose a similar improvement on writability user management than from #3036.
And finally add a mixte handler, both for Global and Channels, with
the advantages of being uniquely created and using less memory and
less shaping.

Issue #2900:

When a huge amount of data are written, the current behavior of the
TrafficShaping handler is to limit the delay to 15s, whatever the delay
the previous write has. This is wrong, and when a huge amount of writes
are done in a short time, the traffic is not correctly shapened.

Moreover, there is a high risk of OOM if one is not using in his/her own
handler for instance ChannelFuture.addListener() to handle the write
bufferisation in the TrafficShapingHandler.

This version includes "user-defined writability" capability added to the channel,
where writability could be managed, using isWritable() only from user handler side.

ChannelInterestChanged is also managed in order to provide compatibility
with other handlers as for instance ChunkedInput.

The "bandwidth" compute on write is only on "acquired" write orders, not
on "real" write orders, which is wrong from statistic point of view.

Issue #2956:

When using GlobalTrafficShaping, every write (and read) were
synchronized, thus leading to a drop of performance.
ChannelTrafficShaping is not touched by this issue since synchronzed is
then correct (handler is per channel, so the synchronized).

Modifications:

The current write delay computation takes into account the previous
write delay and time to check is the 15s delay (maxTime) is really
exceeded or not (using last scheduled write time). The algorithm is
simplified and in the same time more accurate.

A port of the "user-defined writability" as proposed in 4.X is included.

When the real write occurs, the statistics are update accordingly on a
new attribute (getRealWriteThroughput()).

To limit the synchronisations, all synchronized on
GlobalTrafficShapingHandler on submitWrite were removed. They are
replaced with a lock per channel (since synchronization is still needed
to prevent unordered write per channel), as in the sendAllValid method
for the very same reason.
Also all synchronized on TrafficCounter on read/writeTimeToWait() are
removed as they are unnecessary since already locked before by the
caller.
Still the creation and remove operations on lock per channel (PerChannel
object) are synchronized to prevent concurrency issue on this critical
part, but then limited using a ConcurrentHashMap.

Add a Mixte GlobalChannelTrafficShapingHandler which allows to use only one
handler for mixing Global and Channel TSH. I enables to save more memory and
tries to optimize the traffic among various channels.

Add 2 test class: AbstractChannelTest and NioChannelTest
Add test in reverse order in mixed mode

Result:

The traffic shaping is more stable, even with a huge number of writes in
short time by taking into consideration last scheduled write time.

The traffic shaping is more compatible with code as ChunkedWriteHandler,
adding a "user-defined writability".

The statistics are more valuable (asked write vs real write).

The Global TrafficShapingHandler should now have less "global"
synchronization, hoping to the minimum, but still per Channel as needed.

The GlobalChannelTrafficShapingHandler allows to have only one handler for
all channels while still offering per channel in addition to global traffic
shaping.
2014-12-17 13:45:44 +09:00
Jeff Pinner 0a217c328b Remove deprecated methods and classes 2014-12-17 13:20:55 +09:00
Trustin Lee c44c5a0453 [maven-release-plugin] prepare for next development iteration 2014-12-17 13:07:25 +09:00
Trustin Lee f2fdcc9d4f [maven-release-plugin] prepare release netty-3.9.6.Final 2014-12-17 13:07:17 +09:00
luofucong f0503ffb02 Prevent the potential concurrency hazard of the initialization in AbstractNioBoss(Worker)Pool.
Motivation:
During the reading of the source codes of Netty 3.9.5.Final, I thought there might have a lurking concurrency bug in the AbstractNioBossPool#init method, of which a single volatile variable cannot correctly control the initialization sequence happened exactly only once under concurrency environment. Also I found there's already a much more elegant and concurrency safe way to do the work like this, I decided to make this PR. (Please refer to the discussion in https://github.com/netty/netty/issues/3249.)

Modifications:
Change the type of the variable that control the initialization from "volatile boolean" to "final AtomicBoolean".

Result:
The potential concurrency hazard of the initialization in AbstractNioBoss(Worker)Pool will be eliminated.
2014-12-16 17:46:58 +01:00
Frederic Bregier ff9a6e0499 Fix AbstractDiskHttpData int conversion from long
Motivations:
The chunkSize might be oversized after comparison (size being > of int capacity) if file size is bigger than an integer.

Modifications:
Changing the type to long fix the issue.

Result:
There is no more int oversized.
2014-12-08 08:06:37 +01:00
Trustin Lee 03a775a71d Use Triple DES in JdkSslContext cipher suite list.
Related:
- d6c3b3063f
- Original author: @grahamedgecombe

Motivation:

JdkSslContext used SSL_RSA_WITH_DES_CBC_SHA in its cipher suite list.
OpenSslServerContext used DES-CBC3-SHA in the same place in its cipher suite
list, which is equivalent to SSL_RSA_WITH_3DES_EDE_CBC_SHA.

This means the lists were out of sync. Furthermore, using
SSL_RSA_WITH_DES_CBC_SHA is not desirable as it uses DES, a weak cipher. Triple
DES should be used instead.

Modifications:

Replace SSL_RSA_WITH_DES_CBC_SHA with SSL_RSA_WITH_3DES_EDE_CBC_SHA in
JdkSslContext.

Result:

The JdkSslContext and OpenSslServerContext cipher suite lists are now in sync.
Triple DES is used instead of DES, which is stronger.
2014-11-28 15:32:13 +09:00
Trustin Lee 7d9125ed8f Remove or de-prioritize RC4 from default cipher suites
Motivation:

RC4 is not a recommended cipher suite anymore, as the recent research
reveals, such as:

- http://www.isg.rhul.ac.uk/tls/

Modifications:

- Remove most RC4 cipher suites from the default cipher suites
- For backward compatibility, leave RC4-SHA, while de-prioritizing it

Result:

Potentially safer default
2014-11-25 17:24:30 +09:00
Trustin Lee 4772989ddd HTTP Content Encoder allow EmptyLastHttpContent
Related: #3107, origianlly written by @Scottmitch

Motiviation:
The HttpContentEncoder does not account for an EmptyLastHttpContent
being provides as input. This is useful in situations where the client
is unable to determine if the current content chunk is the last content
chunk (i.e. a proxy forwarding content when trnasfer encoding is
chunked)

Modifications:

- HttpContentEncoder should not attempt to compress empty HttpContent
  objects.

Result:

HttpContentEncoder supports a EmptyLastHttpContent to terminate the
response.
2014-11-20 15:25:05 +09:00
Trustin Lee 3451bce17f Backport ZlibTest and fix the bugs revealed
Related: #3107

Motivation:

ZlibEn/Decoder and JdkZlibEncoder in 3.9 do not have any unit tests.
Before applying any patches, we should backport the tests in 4.x so that
we can make sure we do not break anything.

Modification:

- Backport ZlibTest and its subtypes
  - Remove the test for automatic GZIP header detection because the
    ZlibDecoders in 3.9 do not have that feature
- Initialize JdkZlibEncoder.out and crc only when necessary for reduced
  memory footprint
- Fix the bugs in the ZlibEncoders where it fails to compress correctly
  when there are not enough room in the output buffer

Result:

We are more confident when we make changes in ZlibEncoder/Decoder
Bugs have been squashed
2014-11-20 15:19:56 +09:00
Jeff Pinner e30c4fc70f SPDY: add support for pushed resources in SpdyHttpDecoder
Motivation:

The SPDY/3.1 spec does not adequate describe how to push resources
from the server. This was solidified in the HTTP/2 drafts by dividing
the push into two frames, a PushPromise containing the request,
followed by a Headers frame containing the response.

Modifications:

This commit modifies the SpdyHttpDecoder to support pushed resources
that are divided into multiple frames. The decoder will accept a
pushed SpdySynStreamFrame containing the request headers, followed by
a SpdyHeadersFrame containing the response headers.

Result:

The SpdyHttpDecoder will create an HttpRequest object followed by an
HttpResponse object when receiving pushed resources.
2014-11-17 17:59:47 +01:00
Trustin Lee 1c59157b3e Disable SSLv3 (POODLE)
Related: #3131

Motivation:

To prevent users from accidentally enabling SSLv3 and making their
services vulnerable to POODLE, disable SSLv3 when SSLEngine is
instantiated via SslContext.

Modification:

- Disable SSLv3 for JdkSslContext and OpenSslServerContext

Result:

Saner default set of protocols
2014-11-12 16:06:38 +09:00
Trustin Lee 5f80c48eed Backport the new methods and bug fixes in NetUtil
Related:

- 37a6f5ed5d

Motivation:

Minimize the backport cost by synchronizing NetUtil between 3.9 and 4.x

Modifications:

- Backport the bug fixes in NetUtil
- Backport the new IP address methods in NetUtil

Result:

- New useful methods in NetUtil
- Easier to backport the future bug fixes
2014-11-12 12:24:30 +09:00
Trustin Lee 55c2701120 Work around the Javadoc failure in JDK 8
Motivation:

Since JDK 1.8, javadoc has enabled a new feature called 'doclint', which
fails the build when javadoc has markup problems and more.

Modifications:

Do not fail the build until we fix our API documentation.

Result:

No more build failure because of malformed Javadoc
2014-11-12 01:10:05 +09:00
Trustin Lee d708a13d67 Rename from 'The Netty project' to 'Netty'
Motivation:

Sonar uses the project name in the pom.xml as the project name. (no pun
intended) 4.x and master uses 'Netty' as the project name, so we should
be consistent.

Modifications:

Rename the project from 'The Netty project' to 'Netty'

Result:

Prettier SonarQube result
2014-11-03 20:12:16 +09:00
Trustin Lee b644c0096d Remove the unused .travis.yml 2014-11-01 23:04:07 +09:00
Trustin Lee b804c9c34f [maven-release-plugin] prepare for next development iteration 2014-10-30 19:59:35 +09:00