Netty

Clone Tools
  • last updated a few seconds ago
Constraints
Constraints: committers
 
Constraints: files
Constraints: dates
http-proxy: attach headers to connection exception (#8824)

Motivation:

When a proxy fails to connect, it includes useful error detail in

the headers.

Modification:

- Add an HTTP Specific ProxyConnectException

- Attach headers (if any) in the event of a non-200 response

Result:

Able to surface more useful error info to applications

Reduce direct memory overhead per EpollEventLoop when using EpollDatagramChannel (#8825)

Motivation:

When using a linux distribution that supports sendmmsg(...) we allocated enough direct memory per EpollEventLoop to be able to write IOV_MAX number of iovecs per message that can be written per sendmmsg.

The number of messages that can be written per sendmmsg(...) call is limited by UIO_MAX_IOV.

In practice this resulted in an allocation of 16MB direct memory per EpollEventLoop instance that stayed allocated until the EpollEventLoop was shutdown which happens as part of the shutdown of the enclosing EpollEVentLoopGroup.

This resulted in quite some heavy direct memory usage in practice even when in practice we have very slim changes to ever need all of the memory.

Modification:

Adjust NativeDatagramPacketArray to share one IovArray instance across all NativeDatagramPacket instances it holds. This limits the max number of iovecs we can write across all messages to IOV_MAX per sendmmsg(...) call.

This in practice will still be enough to allow us to write multiple messages with one syscall while keep the memory overhead to a minimum.

Result:

Smaller direct memory footprint per EpollEventLoop when using EpollDatagramChannel on distributions that support sendmmsg(...).

Fixes https://github.com/netty/netty/issues/8814

Fix varargs parameter logging in LocationAwareSlf4JLogger (#8834)

Motivation

As pointed out by @91he in

https://github.com/netty/netty/pull/8595#issuecomment-459181794, there

is a remaining bug in LocationAwareSlf4JLogger following the updates

done in #8595. The logging methods which take a varargs message

parameter array should format using MessageFormatter.arrayFormat rather

than MessageFormatter.format.

Modifications

Change varargs param methods in LocationAwareSlf4JLogger to use

MessageFormatter.arrayFormat and extend unit test to cover these cases.

Results

Correct log output when logging messages with > 2 parameters when using

LocationAwareSlf4JLogger.

Replace custome readAllFile method with Files.readAllBytes (#8828)

Motivation:

We can re-use Files.readAllBytes(....) and so can remove our own implementation.

Modification:

Replaced custom readAllBytes with Files.readAllBytes

Result:

Less custom code.

CompositeByteBuf tidy-up (#8784)

Motivation

There's some miscellaneous cleanup/simplification of CompositeByteBuf

which would help make the code a bit clearer.

Modifications

- Simplify web of constructors and addComponents methods, reducing

duplication of logic

- Rename `Component.freeIfNecessary()` method to just `free()`, which is

less confusing (see #8641)

- Make loop in addComponents0(...) method more verbose/readable (see

https://github.com/netty/netty/pull/8437#discussion_r232124414)

- Simplify addition/subtraction in setBytes(...) methods

Result

Smaller/clearer code

Reduce GC produced by native DatagramChannel implementations when in connected mode. (#8806)

Motivation:

In the native code EpollDatagramChannel / KQueueDatagramChannel creates a DatagramSocketAddress object for each received UDP datagram even when in connected mode as it uses the recvfrom(...) / recvmsg(...) method. Creating these is quite heavy in terms of allocations as internally, char[], String, Inet4Address, InetAddressHolder, InetSocketAddressHolder, InetAddress[], byte[] objects are getting generated when constructing the object. When in connected mode we can just use regular read(...) calls which do not need to allocate all of these.

Modifications:

- When in connected mode use read(...) and NOT recvfrom(..) / readmsg(...) to reduce allocations when possible.

- Adjust tests to ensure read works as expected when in connected mode.

Result:

Less allocations and GC when using native datagram channels in connected mode. Fixes https://github.com/netty/netty/issues/8770.

Old cookies classes removed (#8812)

Motivation:

We currently include two different cookie implementations, one is deprecated and one is not. We should remove the deprecated implentation.

Modifications:

Remove deprecated cookies classes.

Result:

Less code to maintain.

Remove ChannelHandler.exceptionCaught(...) as it should only exist in… (#8822)

Motivation:

ChannelHandler.exceptionCaught(...) was marked as @deprecated as it should only exist in inbound handlers.

Modifications:

Remove ChannelHandler.exceptionCaught(...) and adjust code / tests.

Result:

Fixes https://github.com/netty/netty/issues/8527

HttpObjectDecoder ignores HTTP trailer header when empty line is rece… (#8799)

* HttpObjectDecoder ignores HTTP trailer header when empty line is received in seperate ByteBuf

Motivation:

When the empty line that termines the trailers was sent in a seperate ByteBuf we did ignore the previous parsed trailers and just returned none.

Modifications:

- Correct respect previous parsed trailers.

- Add unit test.

Result:

Fixes https://github.com/netty/netty/issues/8736

Remove deprecated HttpHeaders sub classes and related classes (#8813)

Motivation:

Code cleanup;

Changes:

- Removed deprecated HttpHeaders.Names and HttpHeaders.Values sub classes;

- Removed cross reference between EmptyHttpHeaders and HttpHeaders;

- Removed depraced Rtsp* classes;

Result:

Removed deprecated code.

use checkPositive/checkPositiveOrZero (#8803)

Motivation:

We have a utility method to check for > 0 and >0 arguments. We should use it.

Modification:

use checkPositive/checkPositiveOrZero instead of if statement.

Result:

Re-use utility method.

  1. … 17 more files in changeset.
Do not schedule notify task if there are no listeners attached to the promise. (#8797)

Motivation:

If there are no listeners attached to the promise when full-filling it we do not need to schedule a task to notify.

Modifications:

- Don't schedule a task if there is nothing to notify.

- Add unit tests.

Result:

Fixes https://github.com/netty/netty/issues/8795.

Remove HttpHeaderDateFormat class (#8807)

Motivation:

HttpHeaderDateFormat was replaced with DateFormatter many days ago and now can be easily removed.

Modification:

Remove deprecated class and related test / benchmark

Result:

Less code to maintain

Add @Sharable TYPE_USE support for inner class annotations #7756 (#8800)

Motivation:

Make @sharable annotation works with anonymous inner types. Add Java 8 ElementType.TYPE_USE feature that makes easy to use @sharable annotation.

Modification:

transport/src/main/java/io/netty/channel/ChannelHandler.java - Target ElementType.TYPE_USE added.

transport/src/main/java/io/netty/channel/ChannelHandlerAdapter.java - isSharable method improved to verify AnnotatedSuperclass for annotation.

transport/src/test/java/io/netty/channel/ChannelHandlerAdapterTest.java - Tests added.

Result:

ChannelInboundHandler handler = new @Sharable ChannelInboundHandlerAdapter() {

@Override

public void channelRead(ChannelHandlerContext context, Object message) {

context.write(message);

}

};

Note:

The following changes don't support local variable annotation:

ChannelInboundHandler handler1 = new @sharable ChannelInboundHandlerAdapter();

@sharable ChannelInboundHandler handler2 = new ChannelInboundHandlerAdapter();

Fixes #7756

Cleanup DefaultChannelPipeline implementation (#8811)

Motivation:

The DefaultChannelPipeline implementation can be cleaned up a bit and so we can remove the need for AbstractChannelHandlerContext all together.

Modifications:

- Merge DefautChannelHandlerContext and AbstractChannelHandlerContext

- Remove some unnecessary fields

- Some other minor cleanup

Result:

Cleaner code.

Compare HttpMethod by reference (#8815)

Motivation:

In most cases, HttpMethod instance is built from the factory method and the same instance is taken for known Http Methods. So we can implement fast path for equals().

Modification:

Replace == checks with HttpMethod.equals;

Use this == o within HttpMethod.equals;

Replaced known new HttpMethod with HttpMethod.valueOf;

Result:

Comparisons should be a bit faster in some cases.

Remove ability to specify a custom EventExecutor when adding handlers… (#8778)

Motiviation:

In the past we allowed to use different EventExecutors for different ChannelHandlers in the ChannelPipeline. This introduced a lot of complexity while not providing much gain. Also it made the pipeline racy in terms of adding / remove handlers in some situations. This feature is not really used in the wild and can be easily archived by offloading heavy logic to an Executor by the user itself.

Modifications:

- Remove the ability to provide custom EventExecutor when adding handlers to the pipeline.

- Remove testcode that is not needed any more

- Ensure a handler is correctly visible in the pipeline when asked for it by the user while not be used until the EventLoop runs. This ensures correct ordering and visibility.

- Correctly remove ChannelHandlers from pipeline when scheduling of handlerAdded(...) callbacks fail.

Result:

Remove races in DefaultChannelPipeline and simplify implementation of AbstractChannelHandlerContext.

Fix AppendableCharSequence.subSequence(...) where start == end. (#8798)

Motivation:

To conform to the CharSequence interface we need to return an empty CharSequence when start == end index and a subSequence is requested.

Modifications:

- Correctly handle the case where start == end

- Add unit test

Result:

Fix https://github.com/netty/netty/issues/8796.

migrate java8: use lambda and method reference (#8781)

Motivation:

We can use lambdas now as we use Java8.

Modification:

use lambda function for all package, #8751 only migrate transport package.

Result:

Code cleanup.

  1. … 177 more files in changeset.
Drop NPN and SPDY support

Motivation:

NPN has been superseeded by ALPN

SPDY has been superseeded by HTTP/2 and Chrome has dropped support in 2016

Those protocols are deprecated and most likely no longer used at large.

Modifications:

Remove NPN and SPDY code.

`ApplicationProtocolConfig.Protocol` enum is left with 2 values: NONE and ALPN, as this might be more explicit than a boolean and would be more versatile should a new negotiation protocol appear.

Result:

Removed dead code

  1. … 62 more files in changeset.
Minimize memory footprint for AbstractChannelHandlerContext for handlers that execute in the EventExecutor. (#8786)

Motivation:

We cache the Runnable for some tasks to reduce GC pressure in 4 different fields. This gives overhead in terms of memory usage in all cases, even if we always execute in the EventExecutor (which is the case most of the times).

Modifications:

Move the 4 fields to another class and only have one reference to this in AbstractChannelHandlerContext. This gives a small overhead in the case of execution that is done outside of the EventExecutor but reduce memory footprint in the more likily execution case.

Result:

Less memory used per AbstractChannelHandlerContext in most cases.

remove unused import statement (#8792)

Motivation:

The code contained some unused import statements.

Modification:

Remove unused import statements.

Result:

Code cleanup

  1. … 36 more files in changeset.
Remove deprecated SslContext constructors (#8785)

Motivation:

SslContext implementations have tons of contructors, most of them deprecated as we want to enforce builder usage in Netty 5.

Cleaning them up is a requirement prior to introducing new parameters such as hostname verification.

Modifications:

* Make SslContext implementations classes and constructors package private, users are supposed to use the SslContextBuilder.

* Drop all but one constructor. The exception for now is with Jdk(Client|Server)Context that still has an additional constructor that takes an ApplicationProtocolNegotiator parameter. ApplicationProtocolNegotiator usage is supposed to be dropped in favor of ApplicationProtocolConfig and this constructor is only used in tests, so I guess it will be dropped to in a follow up.

Result:

Deprecated code dropped. Path cleaned up for introducing new features with having to introduce yet another constructor.

migrate java8 (#8779)

Motivation:

We can omit argument types when using Java8.

Modification:

Omit arguments where possible.

Result:

Cleaner code.

  1. … 28 more files in changeset.
fix wrong method signature referenced in JavaDoc (#8788)

Motivation:

Recently the code was updated but the java docs was missed.

Modification:

Fix method reference in JavaDoc

Result:

Correct docs.

Java 8 migration: replace anonymous types with lambda (#8751)

Motivation:

We can use lambdas instead of anonymous inner class to improve readablity

Modification:

Replace anonymous inner class with lambda

Result:

Cleaner code that uses Java8 features

  1. … 21 more files in changeset.
Java 8 Migration: remove uneccessary if statement (#8755)

Motivation:

As netty 4.x supported Java 6 we had various if statements to check for java versions < 8. We can remove these now.

Modification:

Remove unnecessary if statements that check for java versions < 8.

Result:

Cleanup code.

  1. … 13 more files in changeset.
Update to new checkstyle plugin (#8777)

Motivation:

We need to update to a new checkstyle plugin to allow the usage of lambdas.

Modifications:

- Update to new plugin version.

- Fix checkstyle problems.

Result:

Be able to use checkstyle plugin which supports new Java syntax.

  1. … 42 more files in changeset.
Fix three bugs in CompositeByteBuf (#8773)

Motivation

In #8758, @doom369 reported an infinite loop bug in CompositeByteBuf

which was introduced in #8437.

This is the same small fix for that, along with fixes for two other bugs

found while re-inspecting the changes and adding unit tests.

Modification

- Replace recursive call to toComponentIndex with toComponentIndex0 as

intended

- Add missed "lastAccessed" racy cache invalidation in capacity(int)

method

- Fix incorrect determination of initial offset in non-zero cIndex case

of updateComponentOffsets method

- New unit tests for previously uncovered methods

Results

Fewer bugs.

Release message when validation of passed in ChannelPromise fails when calling write(...) / writeAndFlush(...) (#8769)

Motivation:

We need to release the message when we throw an IllegalArgumentException because of a validation failure of the promise to eliminate the risk of a memory leak.

Modifications:

- Consistently release the message before rethrow

- Add testcase.

Result:

Fixes https://github.com/netty/netty/issues/8765.