Skip to content

Instantly share code, notes, and snippets.

@jprante
Last active March 8, 2018 15:15
Show Gist options
  • Save jprante/216348c3a9839ab96bad5129baefe631 to your computer and use it in GitHub Desktop.
Save jprante/216348c3a9839ab96bad5129baefe631 to your computer and use it in GitHub Desktop.
Netty ObjectCleanerThread leak?
JorgPrantesMBP:netty-http-client joerg$ ./gradlew test -Dtest.single=SimpleHttp1Test
> Configure project :
Date: 2018-03-08T16:11:42.507832+01:00[Europe/Berlin]
Host: Jorg-Prantes-MacBook-Pro.local/10.1.1.94
OS: Mac OS X x86_64 10.12.6
JVM: 9.0.4.1 9.0.4.1+11 Azul Systems, Inc. OpenJDK 64-Bit Server VM
Gradle: 4.6 Groovy: 2.4.12 Java: 1.9
Build: group: org.xbib name: netty-http-client version: 4.1.22.2
> Task :test
org.xbib.netty.http.client.test.simple.SimpleHttp1Test STANDARD_ERROR
2018-03-08 16:11:43.689 FEIN [io.netty.util.internal.logging.InternalLoggerFactory] io.netty.util.internal.logging.InternalLoggerFactory newDefaultFactory Using java.util.logging as the default logging framework
2018-03-08 16:11:43.704 FEIN [io.netty.util.internal.PlatformDependent] io.netty.util.internal.PlatformDependent isOsx0 Platform: MacOS
2018-03-08 16:11:43.707 FEIN [io.netty.util.internal.PlatformDependent0] io.netty.util.internal.PlatformDependent0 explicitNoUnsafeCause0 -Dio.netty.noUnsafe: false
2018-03-08 16:11:43.707 FEIN [io.netty.util.internal.PlatformDependent0] io.netty.util.internal.PlatformDependent0 javaVersion0 Java version: 9
2018-03-08 16:11:43.708 FEIN [io.netty.util.internal.PlatformDependent0] io.netty.util.internal.PlatformDependent0 <clinit> sun.misc.Unsafe.theUnsafe: available
2018-03-08 16:11:43.709 FEIN [io.netty.util.internal.PlatformDependent0] io.netty.util.internal.PlatformDependent0 <clinit> sun.misc.Unsafe.copyMemory: available
2018-03-08 16:11:43.710 FEIN [io.netty.util.internal.PlatformDependent0] io.netty.util.internal.PlatformDependent0 <clinit> java.nio.Buffer.address: available
2018-03-08 16:11:43.711 FEIN [io.netty.util.internal.PlatformDependent0] io.netty.util.internal.PlatformDependent0 <clinit> direct buffer constructor: unavailable
java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
at io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31)
at io.netty.util.internal.PlatformDependent0$4.run(PlatformDependent0.java:224)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:218)
at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:208)
at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:79)
at io.netty.util.ConstantPool.<init>(ConstantPool.java:32)
at io.netty.util.AttributeKey$1.<init>(AttributeKey.java:27)
at io.netty.util.AttributeKey.<clinit>(AttributeKey.java:27)
at org.xbib.netty.http.client.test.simple.SimpleHttp1Test.<init>(SimpleHttp1Test.java:111)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:116)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:59)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:39)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.base/java.lang.Thread.run(Thread.java:844)
2018-03-08 16:11:43.717 FEIN [io.netty.util.internal.PlatformDependent0] io.netty.util.internal.PlatformDependent0 <clinit> java.nio.Bits.unaligned: unavailable true
java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
at io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31)
at io.netty.util.internal.PlatformDependent0$5.run(PlatformDependent0.java:273)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:266)
at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:208)
at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:79)
at io.netty.util.ConstantPool.<init>(ConstantPool.java:32)
at io.netty.util.AttributeKey$1.<init>(AttributeKey.java:27)
at io.netty.util.AttributeKey.<clinit>(AttributeKey.java:27)
at org.xbib.netty.http.client.test.simple.SimpleHttp1Test.<init>(SimpleHttp1Test.java:111)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:116)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:59)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:39)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.base/java.lang.Thread.run(Thread.java:844)
2018-03-08 16:11:43.722 FEIN [io.netty.util.internal.PlatformDependent0] io.netty.util.internal.PlatformDependent0 <clinit> jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable
java.lang.IllegalAccessException: class io.netty.util.internal.PlatformDependent0$6 cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @64c58de8
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:589)
at java.base/java.lang.reflect.Method.invoke(Method.java:556)
at io.netty.util.internal.PlatformDependent0$6.run(PlatformDependent0.java:315)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:306)
at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:208)
at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:79)
at io.netty.util.ConstantPool.<init>(ConstantPool.java:32)
at io.netty.util.AttributeKey$1.<init>(AttributeKey.java:27)
at io.netty.util.AttributeKey.<clinit>(AttributeKey.java:27)
at org.xbib.netty.http.client.test.simple.SimpleHttp1Test.<init>(SimpleHttp1Test.java:111)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:116)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:59)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:39)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.base/java.lang.Thread.run(Thread.java:844)
2018-03-08 16:11:43.725 FEIN [io.netty.util.internal.PlatformDependent0] io.netty.util.internal.PlatformDependent0 <clinit> java.nio.DirectByteBuffer.<init>(long, int): unavailable
2018-03-08 16:11:43.725 FEIN [io.netty.util.internal.PlatformDependent] io.netty.util.internal.PlatformDependent unsafeUnavailabilityCause0 sun.misc.Unsafe: available
2018-03-08 16:11:43.744 FEIN [io.netty.util.internal.PlatformDependent] io.netty.util.internal.PlatformDependent maxDirectMemory0 maxDirectMemory: 4294967296 bytes (maybe)
2018-03-08 16:11:43.745 FEIN [io.netty.util.internal.PlatformDependent] io.netty.util.internal.PlatformDependent tmpdir0 -Dio.netty.tmpdir: /var/folders/v5/vvl6jhqs0cz_krl674_yb6980000gn/T (java.io.tmpdir)
2018-03-08 16:11:43.745 FEIN [io.netty.util.internal.PlatformDependent] io.netty.util.internal.PlatformDependent bitMode0 -Dio.netty.bitMode: 64 (sun.arch.data.model)
2018-03-08 16:11:43.746 FEIN [io.netty.util.internal.PlatformDependent] io.netty.util.internal.PlatformDependent <clinit> -Dio.netty.noPreferDirect: false
2018-03-08 16:11:43.747 FEIN [io.netty.util.internal.PlatformDependent] io.netty.util.internal.PlatformDependent <clinit> -Dio.netty.maxDirectMemory: -1 bytes
2018-03-08 16:11:43.747 FEIN [io.netty.util.internal.PlatformDependent] io.netty.util.internal.PlatformDependent <clinit> -Dio.netty.uninitializedArrayAllocationThreshold: -1
2018-03-08 16:11:43.748 FEIN [io.netty.util.internal.CleanerJava9] io.netty.util.internal.CleanerJava9 <clinit> java.nio.ByteBuffer.cleaner(): available
org.xbib.netty.http.client.test.simple.SimpleHttp1Test > testHttp1 STANDARD_ERROR
2018-03-08 16:11:43.756 FEIN [io.netty.channel.MultithreadEventLoopGroup] io.netty.channel.MultithreadEventLoopGroup <clinit> -Dio.netty.eventLoopThreads: 16
2018-03-08 16:11:43.781 FEIN [io.netty.channel.nio.NioEventLoop] io.netty.channel.nio.NioEventLoop <clinit> -Dio.netty.noKeySetOptimization: true
2018-03-08 16:11:43.782 FEIN [io.netty.channel.nio.NioEventLoop] io.netty.channel.nio.NioEventLoop <clinit> -Dio.netty.selectorAutoRebuildThreshold: 512
2018-03-08 16:11:43.794 FEIN [io.netty.util.internal.PlatformDependent] io.netty.util.internal.PlatformDependent$Mpsc <clinit> org.jctools-core.MpscChunkedArrayQueue: available
2018-03-08 16:11:43.811 FEIN [io.netty.util.internal.InternalThreadLocalMap] io.netty.util.internal.InternalThreadLocalMap <clinit> -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024
2018-03-08 16:11:43.811 FEIN [io.netty.util.internal.InternalThreadLocalMap] io.netty.util.internal.InternalThreadLocalMap <clinit> -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096
2018-03-08 16:11:43.845 FEIN [io.netty.channel.DefaultChannelId] io.netty.channel.DefaultChannelId <clinit> -Dio.netty.processId: 60480 (auto-detected)
2018-03-08 16:11:43.847 FEIN [io.netty.util.NetUtil] io.netty.util.NetUtil <clinit> -Djava.net.preferIPv4Stack: false
2018-03-08 16:11:43.848 FEIN [io.netty.util.NetUtil] io.netty.util.NetUtil <clinit> -Djava.net.preferIPv6Addresses: false
2018-03-08 16:11:43.852 FEIN [io.netty.util.NetUtil] io.netty.util.NetUtil <clinit> Loopback interface: lo0 (lo0, 0:0:0:0:0:0:0:1%lo0)
2018-03-08 16:11:43.853 FEIN [io.netty.util.NetUtil] io.netty.util.NetUtil$1 run Failed to get SOMAXCONN from sysctl and file /proc/sys/net/core/somaxconn. Default: 128
2018-03-08 16:11:43.855 FEIN [io.netty.channel.DefaultChannelId] io.netty.channel.DefaultChannelId <clinit> -Dio.netty.machineId: 68:5b:35:ff:fe:bc:46:72 (auto-detected)
2018-03-08 16:11:43.865 FEIN [io.netty.util.ResourceLeakDetector] io.netty.util.ResourceLeakDetector <clinit> -Dio.netty.leakDetection.level: paranoid
2018-03-08 16:11:43.866 FEIN [io.netty.util.ResourceLeakDetector] io.netty.util.ResourceLeakDetector <clinit> -Dio.netty.leakDetection.targetRecords: 4
2018-03-08 16:11:43.886 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.numHeapArenas: 16
2018-03-08 16:11:43.887 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.numDirectArenas: 16
2018-03-08 16:11:43.887 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.pageSize: 8192
2018-03-08 16:11:43.887 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.maxOrder: 11
2018-03-08 16:11:43.888 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.chunkSize: 16777216
2018-03-08 16:11:43.888 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.tinyCacheSize: 512
2018-03-08 16:11:43.888 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.smallCacheSize: 256
2018-03-08 16:11:43.889 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.normalCacheSize: 64
2018-03-08 16:11:43.889 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.maxCachedBufferCapacity: 32768
2018-03-08 16:11:43.890 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.cacheTrimInterval: 8192
2018-03-08 16:11:43.890 FEIN [io.netty.buffer.PooledByteBufAllocator] io.netty.buffer.PooledByteBufAllocator <clinit> -Dio.netty.allocator.useCacheForAllThreads: true
2018-03-08 16:11:43.896 FEIN [io.netty.buffer.ByteBufUtil] io.netty.buffer.ByteBufUtil <clinit> -Dio.netty.allocator.type: pooled
2018-03-08 16:11:43.897 FEIN [io.netty.buffer.ByteBufUtil] io.netty.buffer.ByteBufUtil <clinit> -Dio.netty.threadLocalDirectBufferSize: 0
2018-03-08 16:11:43.897 FEIN [io.netty.buffer.ByteBufUtil] io.netty.buffer.ByteBufUtil <clinit> -Dio.netty.maxThreadLocalCharBufferSize: 16384
2018-03-08 16:11:43.920 FEIN [io.netty.buffer.AbstractByteBuf] io.netty.buffer.AbstractByteBuf <clinit> -Dio.netty.buffer.bytebuf.checkAccessible: true
2018-03-08 16:11:43.922 FEIN [io.netty.util.ResourceLeakDetectorFactory] io.netty.util.ResourceLeakDetectorFactory$DefaultResourceLeakDetectorFactory newResourceLeakDetector Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@6c3bf6f2
2018-03-08 16:11:43.925 FEIN [io.netty.buffer.AdvancedLeakAwareByteBuf] io.netty.buffer.AdvancedLeakAwareByteBuf <clinit> -Dio.netty.leakDetection.acquireAndReleaseOnly: false
2018-03-08 16:11:45.774 INFORMATION [org.xbib.netty.http.client.test.simple.SimpleHttp1Test] org.xbib.netty.http.client.test.simple.SimpleHttp1Test sendRequest writing request = DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
GET http://xbib.org:80 HTTP/1.1
host: xbib.org:80
user-agent: Java
accept-encoding: gzip
accept-encoding: deflate
2018-03-08 16:11:45.780 FEIN [io.netty.util.Recycler] io.netty.util.Recycler <clinit> -Dio.netty.recycler.maxCapacityPerThread: 4096
2018-03-08 16:11:45.780 FEIN [io.netty.util.Recycler] io.netty.util.Recycler <clinit> -Dio.netty.recycler.maxSharedCapacityFactor: 2
2018-03-08 16:11:45.780 FEIN [io.netty.util.Recycler] io.netty.util.Recycler <clinit> -Dio.netty.recycler.linkCapacity: 16
2018-03-08 16:11:45.781 FEIN [io.netty.util.Recycler] io.netty.util.Recycler <clinit> -Dio.netty.recycler.ratio: 8
2018-03-08 16:11:45.834 INFORMATION [org.xbib.netty.http.client.test.simple.SimpleHttp1Test] org.xbib.netty.http.client.test.simple.SimpleHttp1Test lambda$testHttp1$1 got response: 200 headers=[Server=nginx/1.4.7, Date=Thu, 08 Mar 2018 15:11:45 GMT, Content-Type=text/html, Content-Length=8444, Last-Modified=Sun, 28 Apr 2013 22:12:04 GMT, Connection=keep-alive, ETag="517d9eb4-20fc", Accept-Ranges=bytes]
2018-03-08 16:11:48.052 INFORMATION [org.xbib.netty.http.client.test.simple.SimpleHttp1Test] org.xbib.netty.http.client.test.simple.SimpleHttp1Test checkThreads threads = 11
2018-03-08 16:11:48.053 FEIN [io.netty.buffer.PoolThreadCache] io.netty.buffer.PoolThreadCache free Freed 3 thread-local buffer(s) from thread: nioEventLoopGroup-2-1
2018-03-08 16:11:48.054 INFORMATION [org.xbib.netty.http.client.test.simple.SimpleHttp1Test] org.xbib.netty.http.client.test.simple.SimpleHttp1Test lambda$checkThreads$0 Thread[ObjectCleanerThread,1,main]
BUILD SUCCESSFUL in 6s
3 actionable tasks: 3 executed
package org.xbib.netty.http.client.test.simple;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.AttributeKey;
import org.junit.After;
import org.junit.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
/**
*
*/
public class SimpleHttp1Test {
private static final Logger logger = Logger.getLogger(SimpleHttp1Test.class.getName());
static {
System.setProperty("io.netty.leakDetection.level", "paranoid");
System.setProperty("io.netty.noKeySetOptimization", Boolean.toString(true));
System.setProperty("java.util.logging.SimpleFormatter.format",
"%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$-7s [%3$s] %2$s %5$s %6$s%n");
LogManager.getLogManager().reset();
Logger rootLogger = LogManager.getLogManager().getLogger("");
Handler handler = new ConsoleHandler();
handler.setFormatter(new SimpleFormatter());
rootLogger.addHandler(handler);
rootLogger.setLevel(Level.ALL);
for (Handler h : rootLogger.getHandlers()) {
handler.setFormatter(new SimpleFormatter());
h.setLevel(Level.ALL);
}
}
@After
public void checkThreads() {
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
logger.log(Level.INFO, "threads = " + threadSet.size() );
threadSet.forEach( thread -> {
if (thread.getName().equals("ObjectCleanerThread")) {
logger.log(Level.INFO, thread.toString());
}
});
}
@Test
public void testHttp1() throws Exception {
Client client = new Client();
try {
HttpTransport transport = client.newTransport("xbib.org", 80);
transport.onResponse(msg -> logger.log(Level.INFO,
"got response: " + msg.status().code() + " headers=" + msg.headers().entries()));
transport.connect();
sendRequest(transport);
transport.awaitResponse();
} finally {
client.shutdown();
}
}
private void sendRequest(HttpTransport transport) {
Channel channel = transport.channel();
if (channel == null) {
return;
}
String host = transport.inetSocketAddress().getHostString();
int port = transport.inetSocketAddress().getPort();
String uri = "http://" + host + ":" + port;
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri);
request.headers().add(HttpHeaderNames.HOST, host + ":" + port);
request.headers().add(HttpHeaderNames.USER_AGENT, "Java");
request.headers().add(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP);
request.headers().add(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.DEFLATE);
logger.log(Level.INFO, () -> "writing request = " + request);
if (channel.isWritable()) {
channel.writeAndFlush(request);
}
}
private AttributeKey<HttpTransport> TRANSPORT_ATTRIBUTE_KEY = AttributeKey.valueOf("transport");
interface ResponseWriter {
void write(FullHttpResponse msg);
}
class Client {
private final EventLoopGroup eventLoopGroup;
private final Bootstrap bootstrap;
private final HttpResponseHandler httpResponseHandler;
private final Initializer initializer;
private final List<HttpTransport> transports;
Client() {
eventLoopGroup = new NioEventLoopGroup();
httpResponseHandler = new HttpResponseHandler();
initializer = new Initializer(httpResponseHandler);
bootstrap = new Bootstrap()
.group(eventLoopGroup)
.channel(NioSocketChannel.class)
.handler(initializer);
transports = new ArrayList<>();
}
Bootstrap bootstrap() {
return bootstrap;
}
void shutdown() {
close();
eventLoopGroup.shutdownGracefully();
try {
eventLoopGroup.awaitTermination(10L, TimeUnit.SECONDS);
} catch (InterruptedException e) {
logger.log(Level.WARNING, e.getMessage(), e);
}
}
HttpTransport newTransport(String host, int port) {
HttpTransport transport = new HttpTransport(this, new InetSocketAddress(host, port));
transports.add(transport);
return transport;
}
synchronized void close() {
for (HttpTransport transport : transports) {
transport.close();
}
transports.clear();
}
}
class HttpTransport {
private final Client client;
private final InetSocketAddress inetSocketAddress;
private Channel channel;
private CompletableFuture<Boolean> promise;
private ResponseWriter responseWriter;
HttpTransport(Client client, InetSocketAddress inetSocketAddress ) {
this.client = client;
this.inetSocketAddress = inetSocketAddress;
}
InetSocketAddress inetSocketAddress() {
return inetSocketAddress;
}
void connect() throws InterruptedException {
channel = client.bootstrap().connect(inetSocketAddress).sync().await().channel();
channel.attr(TRANSPORT_ATTRIBUTE_KEY).set(this);
promise = new CompletableFuture<>();
}
Channel channel() {
return channel;
}
void onResponse(ResponseWriter responseWriter) {
this.responseWriter = responseWriter;
}
void responseReceived(FullHttpResponse msg) {
if (responseWriter != null) {
responseWriter.write(msg);
}
}
void awaitResponse() {
if (promise != null) {
try {
promise.get(5, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.log(Level.WARNING, e.getMessage(), e);
}
}
}
void complete() {
if (promise != null) {
promise.complete(true);
}
}
void fail(Throwable throwable) {
if (promise != null) {
promise.completeExceptionally(throwable);
}
}
void close() {
if (channel != null) {
channel.close();
}
}
}
class Initializer extends ChannelInitializer<SocketChannel> {
private HttpResponseHandler httpResponseHandler;
Initializer(HttpResponseHandler httpResponseHandler) {
this.httpResponseHandler = httpResponseHandler;
}
@Override
protected void initChannel(SocketChannel ch) {
ch.pipeline().addLast(new HttpClientCodec());
ch.pipeline().addLast(new HttpObjectAggregator(1048576));
ch.pipeline().addLast(httpResponseHandler);
}
}
class HttpResponseHandler extends SimpleChannelInboundHandler<FullHttpResponse> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) {
HttpTransport transport = ctx.channel().attr(TRANSPORT_ATTRIBUTE_KEY).get();
if (msg.content().isReadable()) {
transport.responseReceived(msg);
}
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
HttpTransport transport = ctx.channel().attr(TRANSPORT_ATTRIBUTE_KEY).get();
transport.complete();
}
@Override
public void channelInactive(ChannelHandlerContext ctx) {
ctx.fireChannelInactive();
HttpTransport transport = ctx.channel().attr(TRANSPORT_ATTRIBUTE_KEY).get();
transport.fail(new IOException("channel closed"));
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
logger.log(Level.SEVERE, cause.getMessage(), cause);
HttpTransport transport = ctx.channel().attr(TRANSPORT_ATTRIBUTE_KEY).get();
transport.fail(cause);
ctx.channel().close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment