Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE at HttpClientOperations.isWebsocket #342

Closed
lhotari opened this issue May 1, 2018 · 7 comments
Closed

NPE at HttpClientOperations.isWebsocket #342

lhotari opened this issue May 1, 2018 · 7 comments
Labels
type/bug A general bug
Milestone

Comments

@lhotari
Copy link
Contributor

lhotari commented May 1, 2018

Expected behavior

Calling HttpClientOperations.isWebsocket shouldn't throw a NPE.

Actual behavior

NPE gets thrown in some cases:

java.lang.NullPointerException: null
	at reactor.ipc.netty.http.client.HttpClientOperations.isWebsocket(HttpClientOperations.java:325) ~[reactor-netty-0.7.7.BUILD-SNAPSHOT.jar!/:0.7.7.BUILD-SNAPSHOT]
	at reactor.ipc.netty.http.client.HttpClientOperations.onOutboundComplete(HttpClientOperations.java:506) ~[reactor-netty-0.7.7.BUILD-SNAPSHOT.jar!/:0.7.7.BUILD-SNAPSHOT]
	at reactor.ipc.netty.channel.ChannelOperations.onComplete(ChannelOperations.java:219) ~[reactor-netty-0.7.7.BUILD-SNAPSHOT.jar!/:0.7.7.BUILD-SNAPSHOT]
	at reactor.core.publisher.Operators$MonoSubscriber.onComplete(Operators.java:1111) ~[reactor-core-3.1.7.BUILD-SNAPSHOT.jar!/:3.1.7.BUILD-SNAPSHOT]
	at reactor.core.publisher.MonoIgnoreThen$ThenAcceptInner.onComplete(MonoIgnoreThen.java:308) ~[reactor-core-3.1.7.BUILD-SNAPSHOT.jar!/:3.1.7.BUILD-SNAPSHOT]
	at reactor.ipc.netty.FutureMono$ChannelFutureSubscription.setSuccess(FutureMono.java:367) ~[reactor-netty-0.7.7.BUILD-SNAPSHOT.jar!/:0.7.7.BUILD-SNAPSHOT]
	at io.netty.channel.DefaultChannelPromise.setSuccess(DefaultChannelPromise.java:73) ~[netty-transport-4.1.24.Final.jar!/:4.1.24.Final]
	at reactor.ipc.netty.channel.ChannelOperationsHandler$PublisherSender.onComplete(ChannelOperationsHandler.java:583) ~[reactor-netty-0.7.7.BUILD-SNAPSHOT.jar!/:0.7.7.BUILD-SNAPSHOT]
	at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:130) ~[reactor-core-3.1.7.BUILD-SNAPSHOT.jar!/:3.1.7.BUILD-SNAPSHOT]
	at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:130) ~[reactor-core-3.1.7.BUILD-SNAPSHOT.jar!/:3.1.7.BUILD-SNAPSHOT]
	at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:245) ~[reactor-core-3.1.7.BUILD-SNAPSHOT.jar!/:3.1.7.BUILD-SNAPSHOT]
	at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:130) ~[reactor-core-3.1.7.BUILD-SNAPSHOT.jar!/:3.1.7.BUILD-SNAPSHOT]
	at reactor.core.publisher.Operators.complete(Operators.java:125) ~[reactor-core-3.1.7.BUILD-SNAPSHOT.jar!/:3.1.7.BUILD-SNAPSHOT]
	at reactor.ipc.netty.channel.FluxReceive.startReceiver(FluxReceive.java:267) ~[reactor-netty-0.7.7.BUILD-SNAPSHOT.jar!/:0.7.7.BUILD-SNAPSHOT]
	at reactor.ipc.netty.channel.FluxReceive.lambda$subscribe$2(FluxReceive.java:127) ~[reactor-netty-0.7.7.BUILD-SNAPSHOT.jar!/:0.7.7.BUILD-SNAPSHOT]
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[netty-common-4.1.24.Final.jar!/:4.1.24.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) [netty-common-4.1.24.Final.jar!/:4.1.24.Final]
	at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:309) [netty-transport-native-epoll-4.1.24.Final-linux-x86_64.jar!/:4.1.24.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) [netty-common-4.1.24.Final.jar!/:4.1.24.Final]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_152]

Steps to reproduce

Reproducing the issue might be hard. I did this to get the error, the error appeared in the gateway logs:

git clone https://github.com/lhotari/spring-cloud-gw-issue-228
cd spring-cloud-gw-issue-228
mvn package
# terminal 1
java -jar apigw-test-ms/target/apigw-test-ms-exec.jar
# terminal 2
java -Dspring.cloud.gateway.httpclient.pool.type=DISABLED -jar gateway/target/gateway-0.0.1-SNAPSHOT.jar
# terminal 3
java -jar test-driver/target/test-driver-1.0.0.jar

I was able to reproduce the issue twice. On the first time, it took about 2 minutes to reproduce and on the second time, it took over 7 minutes to reproduce.

Reactor Netty version

0.7.7.BUILD-SNAPSHOT (ac103c0)

JVM version (e.g. java -version)

openjdk version "1.8.0_152"
OpenJDK Runtime Environment (Zulu 8.25.0.1-linux64) (build 1.8.0_152-b16)
OpenJDK 64-Bit Server VM (Zulu 8.25.0.1-linux64) (build 25.152-b16, mixed mode)

OS version (e.g. uname -a)

Linux 4.13.0-39-generic #44~16.04.1-Ubuntu

@lhotari lhotari changed the title NPE at reactor.ipc.netty.http.client.HttpClientOperations.isWebsocket NPE at HttpClientOperations.isWebsocket May 1, 2018
@violetagg
Copy link
Member

java -Dspring.cloud.gateway.httpclient.pool.type=DISABLED -jar gateway/target/gateway-0.0.1-SNAPSHOT.jar

@lhotari just to clarify that we need to disable the pool in order to reproduce the issue. Is that correct?

@lhotari
Copy link
Contributor Author

lhotari commented May 1, 2018

@violetagg yes, that's the case.

@violetagg
Copy link
Member

violetagg commented May 1, 2018

@lhotari can you try this fix #343. I think that NPE is just a side effect of #323

@violetagg violetagg added this to the 0.7.7.RELEASE milestone May 1, 2018
@violetagg violetagg added the type/bug A general bug label May 1, 2018
@lhotari
Copy link
Contributor Author

lhotari commented May 1, 2018

@violetagg I tested with the issue-323 branch (dac97b5). The NPE still occurs with that change.

@violetagg
Copy link
Member

@lhotari ok the cause is still the same #323 but we need that check for NULL also. Please try the new version of the change.

Thanks a lot

@lhotari
Copy link
Contributor Author

lhotari commented May 1, 2018

@violetagg yes, that fixed the NPE. Thank you

violetagg added a commit that referenced this issue May 1, 2018
…uest, force the channel close

As the onHandlerTerminate will be invoked and it will remove the ChannelOperations from the
channel attributes, when the onOutboundComplete is invoked while checking for websocket
the implementation needs to take into account that the ChannelOperations might be removed already.
This is related to issue #342
@violetagg
Copy link
Member

fixed by 4a2e773

thanks for testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants