grpc-java: [Help wanted] io.grpc.okhttp.OkHttpClientTransportTest fails in Mac and GitHub Actions
In master, I cannot build :grpc-okhttp module because OkHttpClientTransportTest fails in my Mac (Mac OS 11.2.3) and GitHub Actions (link).
suztomo-macbookpro44% git log -1
commit d4fa0ecc07495097453b0a2848765f076b9e714c (HEAD -> master, origin/master, origin/HEAD)
Author: Chengyuan Zhang <chengyuanzhang@google.com>
Date: Mon Apr 12 14:55:31 2021 -0700
...(omit)...
suztomo-macbookpro44% cat gradle.properties
skipCodegen=true
skipAndroid=true
suztomo-macbookpro44% ./gradlew cleanTest :grpc-okhttp:test --tests=io.grpc.okhttp.OkHttpClientTransportTest
*** Skipping the build of codegen and compilation of proto files because skipCodegen=true
* Skipping the build of Android projects because skipAndroid=true
> Task :grpc-okhttp:test
io.grpc.okhttp.OkHttpClientTransportTest > proxy_200 FAILED
org.junit.runners.model.TestTimedOutException: test timed out after 10 seconds
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
at java.net.ServerSocket.implAccept(ServerSocket.java:545)
at java.net.ServerSocket.accept(ServerSocket.java:513)
at io.grpc.okhttp.OkHttpClientTransportTest.proxy_200(OkHttpClientTransportTest.java:1876)
io.grpc.okhttp.OkHttpClientTransportTest > proxy_500 FAILED
org.junit.runners.model.TestTimedOutException: test timed out after 10 seconds
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
at java.net.ServerSocket.implAccept(ServerSocket.java:545)
at java.net.ServerSocket.accept(ServerSocket.java:513)
at io.grpc.okhttp.OkHttpClientTransportTest.proxy_500(OkHttpClientTransportTest.java:1933)
io.grpc.okhttp.OkHttpClientTransportTest > proxy_immediateServerClose FAILED
org.junit.runners.model.TestTimedOutException: test timed out after 10 seconds
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
at java.net.ServerSocket.implAccept(ServerSocket.java:545)
at java.net.ServerSocket.accept(ServerSocket.java:513)
at io.grpc.okhttp.OkHttpClientTransportTest.proxy_immediateServerClose(OkHttpClientTransportTest.java:1989)
68 tests completed, 3 failed
> Task :grpc-okhttp:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':grpc-okhttp:test'.
> There were failing tests. See the report at: file:///Users/suztomo/grpc-java/okhttp/build/reports/tests/test/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 34s
58 actionable tasks: 3 executed, 55 up-to-date
The build works fine in my Debian machine. (I also see this repository has setup Travis CI enabled.)
suztomo@suztomo:~/grpc-java$ ./gradlew cleanTest :grpc-okhttp:test --tests=io.grpc.okhttp.OkHttpClientTransportTest
*** Skipping the build of codegen and compilation of proto files because skipCodegen=true
* Skipping the build of Android projects because skipAndroid=true
BUILD SUCCESSFUL in 5s
58 actionable tasks: 2 executed, 56 up-to-date
Therefore I think I’ll need to setup something for the failing environment to make the test pass.
While I continue to dig further, I appreciate if anyone know the prerequisite for OkHttpClientTransportTest.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (15 by maintainers)
Commits related to this issue
- OkHttpClientTransportTest's proxy to use loopback address Fixes #8080. The address 0.0.0.0 (that comes from new Socket(0). .getLocalSocketAddress()) is for listening with a server, but it is not mean... — committed to suztomo/grpc-java by suztomo 3 years ago
- OkHttpClientTransportTest's proxy to use localhost Fixes #8080. The address 0.0.0.0 (that comes from new Socket(0). .getLocalSocketAddress()) is for listening with a server, but it is not meant to be... — committed to suztomo/grpc-java by suztomo 3 years ago
- okhttp: During testing, bind to localhost instead of 0.0.0.0 The server's address is used by the client to determine where to connect. When binding to 0.0.0.0 the address returned by getLocalSocketAd... — committed to ejona86/grpc-java by ejona86 3 years ago
- OkHttpClientTransportTest's proxy to use localhost Fixes #8080. The address 0.0.0.0 (that comes from new Socket(0). .getLocalSocketAddress()) is for listening with a server, but it is not meant to be... — committed to grpc/grpc-java by suztomo 3 years ago
@ejona86
new ServerSocket(0, 0, InetAddress.getLoopbackAddress())
solved the problem!Now
proxy_immediateServerClose
succeeds:This time standard output captured the invocation argument:
@ejona86 @sanjaypujare Thank you for your help in troubleshooting!
My Memo
Why
ServerSocket(0)
does not work?ServerSocket(0)
isServerSocket(port: 0, backlog: 50, bindAddr: null)
.(
ServerSocket serverSocket = new ServerSocket(0, 50, loopbackAddress);
also works good.)https://docs.oracle.com/javase/8/docs/api/java/net/ServerSocket.html says:
InetAddress.getLoopbackAddress()
returnsInet4Address@2726 localhost/127.0.0.1
.How about ServerSocket(0, 50, null)?
This timed out… (Of course
ServerSocket(0)
is the alias toServerSocket(0, 50, null)
)How about 0.0.0.0?
This timed out…
How about 127.0.0.1?
This worked!
Any security system that blocks listening on 0.0.0.0 port 80?
In my Mac,
nc
command can listen on 0.0.0.0 port 80.What’s the difference in the client code?
when I use
InetAddress.getLoopbackAddress()
, then the client’sSocketFactory.createSocket
takes 127.0.0.1.In the bad case, the client was trying to create a socket to 0.0.0.0 (screenshot). As per https://serverfault.com/a/300408 (which mentions https://tools.ietf.org/html/rfc1122#page-30 ), address 0.0.0.0 must not be sent.
How about specifying proxyAddress with InetAddress.getLoopbackAddress?
The code below also worked and clarifies the difference between the bad case and good case: