Clone
 

trustin lee <t@motd.kr> in Netty

Update os-maven-plugin to 1.6.0 (#7884)

Motivation:

A new version of os-maven-plugin has been released.

Modifications:

- Update os-maven-plugin from 1.5.0 to 1.6.0

Result:

- No visible changes

- Feels good

Update os-maven-plugin to 1.6.0

Motivation:

A new version of os-maven-plugin has been released.

Modifications:

- Update os-maven-plugin from 1.5.0 to 1.6.0

Result:

- No visible changes

- Feels good

Add DnsNameResolver.resolveAll(DnsQuestion) (#7803)

* Add DnsNameResolver.resolveAll(DnsQuestion)

Motivation:

A user is currently expected to use DnsNameResolver.query() when he or

she wants to look up the full DNS records rather than just InetAddres.

However, query() only performs a single query. It does not handle

/etc/hosts file, redirection, CNAMEs or multiple name servers.

As a result, such a user has to duplicate all the logic in

DnsNameResolverContext.

Modifications:

- Refactor DnsNameResolverContext so that it can send queries for

arbitrary record types.

- Rename DnsNameResolverContext to DnsResolveContext

- Add DnsAddressResolveContext which extends DnsResolveContext for

A/AAAA lookup

- Add DnsRecordResolveContext which extends DnsResolveContext for

arbitrary lookup

- Add DnsNameResolverContext.resolveAll(DnsQuestion) and its variants

- Change DnsNameResolverContext.resolve() delegates the resolve request

to resolveAll() for simplicity

- Move the code that decodes A/AAAA record content to DnsAddressDecoder

Result:

- Fixes #7795

- A user does not have to duplicate DnsNameResolverContext in his or her

own code to implement the usual DNS resolver behavior.

Address comments

Add DnsNameResolver.resolveAll(DnsQuestion)

Motivation:

A user is currently expected to use DnsNameResolver.query() when he or

she wants to look up the full DNS records rather than just InetAddres.

However, query() only performs a single query. It does not handle

/etc/hosts file, redirection, CNAMEs or multiple name servers.

As a result, such a user has to duplicate all the logic in

DnsNameResolverContext.

Modifications:

- Refactor DnsNameResolverContext so that it can send queries for

arbitrary record types.

- Rename DnsNameResolverContext to DnsResolveContext

- Add DnsAddressResolveContext which extends DnsResolveContext for

A/AAAA lookup

- Add DnsRecordResolveContext which extends DnsResolveContext for

arbitrary lookup

- Add DnsNameResolverContext.resolveAll(DnsQuestion) and its variants

- Change DnsNameResolverContext.resolve() delegates the resolve request

to resolveAll() for simplicity

- Move the code that decodes A/AAAA record content to DnsAddressDecoder

Result:

- Fixes #7795

- A user does not have to duplicate DnsNameResolverContext in his or her

own code to implement the usual DNS resolver behavior.

Add DnsNameResolver.resolveAll(DnsQuestion)

Motivation:

A user is currently expected to use DnsNameResolver.query() when he or

she wants to look up the full DNS records rather than just InetAddres.

However, query() only performs a single query. It does not handle

/etc/hosts file, redirection, CNAMEs or multiple name servers.

As a result, such a user has to duplicate all the logic in

DnsNameResolverContext.

Modifications:

- Refactor DnsNameResolverContext so that it can send queries for

arbitrary record types.

- Rename DnsNameResolverContext to DnsResolveContext

- Add DnsAddressResolveContext which extends DnsResolveContext for

A/AAAA lookup

- Add DnsRecordResolveContext which extends DnsResolveContext for

arbitrary lookup

- Add DnsNameResolverContext.resolveAll(DnsQuestion) and its variants

- Change DnsNameResolverContext.resolve() delegates the resolve request

to resolveAll() for simplicity

- Move the code that decodes A/AAAA record content to DnsAddressDecoder

Result:

- Fixes #7795

- A user does not have to duplicate DnsNameResolverContext in his or her

own code to implement the usual DNS resolver behavior.

WIP

Add the NOTICE of the forked portion of Apache Harmony

Motivation:

According to the section 4d of ASLv2:

If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

Modifications:

- Add a subset of NOTICE.txt of Apache Harmony.

Result:

- Fixes #7588

    • -0
    • +6
    /license/NOTICE.harmony.txt
Add the NOTICE of the forked portion of Apache Harmony

Motivation:

According to the section 4d of ASLv2:

If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

Modifications:

- Add a subset of NOTICE.txt of Apache Harmony.

Result:

- Fixes #7588

Add the NOTICE of the forked portion of Apache Harmony

Motivation:

According to the section 4d of ASLv2:

If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

Modifications:

- Add a subset of NOTICE.txt of Apache Harmony.

Result:

- Fixes #7588

    • -0
    • +6
    /license/NOTICE.harmony.txt
Do not fail a DNS query promise prematurely

Motivation:

DnsNameResolverContext completes its DNS query promise automatically

when no queries are in progress, which means there's no need to fail the

promise explicitly.

Modifications:

- Do not fail a DNS query promise explicitly but add an informational

trace

Result:

- Fixes #6600

- Unexpected exception on one question type does not fail the promise

too soon. If the other question succeeds, the query will succeed,

making the resolver more robust.

Do not fail a DNS query promise prematurely

Motivation:

DnsNameResolverContext completes its DNS query promise automatically

when no queries are in progress, which means there's no need to fail the

promise explicitly.

Modifications:

- Do not fail a DNS query promise explicitly but add an informational

trace

Result:

- Fixes #6600

- Unexpected exception on one question type does not fail the promise

too soon. If the other question succeeds, the query will succeed,

making the resolver more robust.

Do not fail a DNS query promise prematurely

Motivation:

DnsNameResolverContext completes its DNS query promise automatically

when no queries are in progress, which means there's no need to fail the

promise explicitly.

Modifications:

- Do not fail a DNS query promise explicitly but add an informational

trace

Result:

- Fixes #6600

- Unexpected exception on one question type does not fail the promise

too soon. If the other question succeeds, the query will succeed,

making the resolver more robust.

Convert X509TrustManager into X509ExtendedTrustManager for Java 7+

Motivation:

Since Java 7, X509TrustManager implementation is wrapped by a JDK class

called AbstractTrustManagerWrapper, which performs an additional

certificate validation for Socket or SSLEngine-backed connections.

This makes the TrustManager implementations provided by

InsecureTrustManagerFactory and FingerprintTrustManagerFactory not

insecure enough, where their certificate validation fails even when it

should pass.

Modifications:

- Add X509TrustManagerWrapper which adapts an X509TrustManager into an

X509ExtendedTrustManager

- Make SimpleTrustManagerFactory wrap an X509TrustManager with

X509TrustManagerWrapper is the provided TrustManager does not extend

X509ExtendedTrustManager

Result:

- InsecureTrustManagerFactory and FingerprintTrustManagerFactory are now

insecure as expected.

- Fixes #5910

Convert X509TrustManager into X509ExtendedTrustManager for Java 7+

Motivation:

Since Java 7, X509TrustManager implementation is wrapped by a JDK class

called AbstractTrustManagerWrapper, which performs an additional

certificate validation for Socket or SSLEngine-backed connections.

This makes the TrustManager implementations provided by

InsecureTrustManagerFactory and FingerprintTrustManagerFactory not

insecure enough, where their certificate validation fails even when it

should pass.

Modifications:

- Add X509TrustManagerWrapper which adapts an X509TrustManager into an

X509ExtendedTrustManager

- Make SimpleTrustManagerFactory wrap an X509TrustManager with

X509TrustManagerWrapper is the provided TrustManager does not extend

X509ExtendedTrustManager

Result:

- InsecureTrustManagerFactory and FingerprintTrustManagerFactory are now

insecure as expected.

- Fixes #5910

Fix native library loading in Windows

Motivation:

Windows refuses to load a .DLL file when it's opened by other process.

Recent modification in NativeLibraryLoader causes NativeLibraryLoader to

attempt to load a .DLL before closing its OutputStream. As a result,

loading a .DLL file in Windows always fails.

Modifications:

Close the OutputStream explicitly before loading a shared library.

Result:

Native library loading in Windows works again.

Fix native library loading in Windows

Motivation:

Windows refuses to load a .DLL file when it's opened by other process.

Recent modification in NativeLibraryLoader causes NativeLibraryLoader to

attempt to load a .DLL before closing its OutputStream. As a result,

loading a .DLL file in Windows always fails.

Modifications:

Close the OutputStream explicitly before loading a shared library.

Result:

Native library loading in Windows works again.

Fulfill the write promise of empty HTTP/2 DATA frames sooner

Motivation:

DefaultHttp2ConnectionEncoder.FlowControlledData.write() does not

complete the write promise of empty HTTP/2 DATA frames until either a

non-DATA frame, a non-empty DATA frame or a DATA frame with endOfStream

set. This makes the write promise of the empty DATA frame is notified

much later than it could be.

Modifications:

- Notify the write promise of the empty DATA frames immediately is the

queue contains empty DATA frames only

Result:

The write promise of an empty DATA frame is notified sooner.

Disable IPv6 address lookups when -Djava.net.preferIPv4Stack=true

Motivation:

According to the Oracle documentation:

> java.net.preferIPv4Stack (default: false)

>

> If IPv6 is available on the operating system, the underlying native

> socket will be an IPv6 socket. This allows Java applications to connect

> to, and accept connections from, both IPv4 and IPv6 hosts.

>

> If an application has a preference to only use IPv4 sockets, then this

> property can be set to true. The implication is that the application

> will not be able to communicate with IPv6 hosts.

which means, if DnsNameResolver returns an IPv6 address, a user (or

Netty) will not be able to connect to it.

Modifications:

- Move the code that retrieves java.net.prefer* properties from

DnsNameResolver to NetUtil

- Add NetUtil.isIpV6AddressesPreferred()

- Revise the API documentation of NetUtil.isIpV*Preferred()

- Set the default resolveAddressTypes to IPv4 only when

NetUtil.isIpv4StackPreferred() returns true

Result:

- Fixes #5657

    • -2
    • +25
    /common/src/main/java/io/netty/util/NetUtil.java
Fix RejectedExecutionException when using DnsAddressResolverGroup

Motivation:

AddressResolverGroup adds a listener to the termination future of an

EventExecutor when a new AddressResolver is created. The listener calls

AddressResolver.close() when the EventExecutor is terminated to give the

AddressResolver a chance to release its resources.

When using DnsAddressResolverGroup, the AddressResolver.close() will

eventually trigger DnsNameResolver.close(), which closes its underlying

DatagramChannel.

DatagramChannel.close() (or any Channel.close()) will travel through

pipeline and trigger EventExecutor.execute() because

DnsNameResolver.close() has been invoked from a non-I/O thread.

(NB: A terminationFuture is always notified from the GlobalEventExecutor

thread.)

However, because we are doing this in the listener of the termination

future of the terminated EventLoop we are trying to execute a task upon,

the attempt to close the channel fails due to RejectedExecutionException.

Modifications:

- Do not call Channel.close() in DnsNameResolver.close() if the Channel

has been closed by EventLoop already

Result:

No more RejectedExecutionException when shutting down an event loop.

Fix NPE when creating DomainNameMapping via a builder

Fix NPE when creating DomainNameMapping via a builder

Replace DomainMappingBuilder with DomainNameMappingBuilder

Motivation:

DomainMappingBuilder should have been named as DomainNameMappingBuilder

because it builds a DomainNameMapping.

Modifications:

- Add DomainNameMappingBuilder that does the same job with

DomainMappingBuilder

- Deprecate DomainMappingBuilder and delegate its logic to

DomainNameMappingBuilder

- Remove the references to the deprecated methods and classes related

with domain name mapping

- Miscellaneous:

- Fix Javadoc of DomainNameMapping.asMap()

- Pre-create the unmodifiable map in DomainNameMapping

Result:

- Consistent naming

- Less use of deprecated API

    • -0
    • +204
    /common/src/main/java/io/netty/util/DomainNameMappingBuilder.java
Replace DomainMappingBuilder with DomainNameMappingBuilder

Motivation:

DomainMappingBuilder should have been named as DomainNameMappingBuilder

because it builds a DomainNameMapping.

Modifications:

- Add DomainNameMappingBuilder that does the same job with

DomainMappingBuilder

- Deprecate DomainMappingBuilder and delegate its logic to

DomainNameMappingBuilder

- Remove the references to the deprecated methods and classes related

with domain name mapping

- Miscellaneous:

- Fix Javadoc of DomainNameMapping.asMap()

- Pre-create the unmodifiable map in DomainNameMapping

Result:

- Consistent naming

- Less use of deprecated API

    • -0
    • +204
    /common/src/main/java/io/netty/util/DomainNameMappingBuilder.java
Replace DomainNameMapping.entries() with asMap()

Motivation:

DomainNameMapping.entries() returns Set<Map.Entry<String, V>>, which

doesn't sound very natural.

Modifications:

Replace entries() with asMap() which returns a Map<String, V> instead.

Result:

- Better looking API

- User can do a lookup because it's a Map

Replace DomainNameMapping.entries() with asMap()

Motivation:

DomainNameMapping.entries() returns Set<Map.Entry<String, V>>, which

doesn't sound very natural.

Modifications:

Replace entries() with asMap() which returns a Map<String, V> instead.

Result:

- Better looking API

- User can do a lookup because it's a Map

Do not send duplicate DNS queries when the same query is in progress already

Related issue: #5179

Motivation:

When you attempt to make a lot of connection attempts to the same target

host at the same time and our DNS resolver does not have a record for it

in the cache, the DNS resolver will send as many DNS queries as the

number of connection attempts.

As a result, DNS server will reject or drop the requests, making the

name resolution attempt fail.

Modifications:

- Add InflightNameResolver that keeps the list of name resolution

queries and subscribes to the future of the matching query instead of

sending a duplicate query.

Result:

- The AddressResolvers created by DnsAddressResolverGroup do not send

duplicate DNS queries anymore

Reorganize imports

Make retained derived buffers recyclable

Related: #4333 #4421 #5128

Motivation:

slice(), duplicate() and readSlice() currently create a non-recyclable

derived buffer instance. Under heavy load, an application that creates a

lot of derived buffers can put the garbage collector under pressure.

Modifications:

- Add the following methods which creates a non-recyclable derived buffer

- retainedSlice()

- retainedDuplicate()

- readRetainedSlice()

- Add the new recyclable derived buffer implementations, which has its

own reference count value

- Add ByteBufHolder.retainedDuplicate()

- Add ByteBufHolder.replace(ByteBuf) so that..

- a user can replace the content of the holder in a consistent way

- copy/duplicate/retainedDuplicate() can delegate the holder

construction to replace(ByteBuf)

- Use retainedDuplicate() and retainedSlice() wherever possible

- Miscellaneous:

- Rename DuplicateByteBufTest to DuplicatedByteBufTest (missing 'D')

- Make ReplayingDecoderByteBuf.reject() return an exception instead of

throwing it so that its callers don't need to add dummy return

statement

Result:

Derived buffers are now recycled when created via retainedSlice() and

retainedDuplicate() and derived from a pooled buffer

  1. … 117 more files in changeset.
Implement the ByteBuf methods that should have been overridden

Motivation:

Some ByteBuf implementations do not override all necessary methods,

which can lead to potentially sub-optimal behavior.

Also, SlicedByteBuf does not perform the range check correctly due to

missing overrides.

Modifications:

- Add missing overrides

- Use unwrap() instead of direct member access in derived buffers for

consistency

- Merge unwrap0() into unwrap() using covariant return type

- Deprecate AbstractDerivedByteBuf and its subtypes, because they were

not meant to be public

Result:

Correctness