首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当应用程序端"echo > /dev/tcp/localhost/8877“时出现异常

当应用程序端"echo > /dev/tcp/localhost/8877“时出现异常
EN

Stack Overflow用户
提问于 2020-10-14 09:04:57
回答 1查看 234关注 0票数 0

使用bash脚本测试Java应用程序的可用性。

脚本通过以下方式确定应用程序的可用性:

代码语言:javascript
复制
echo > /dev/tcp/<apps-ip>/8877 
e.g. echo > /dev/tcp/localhost/8877

但是,这会导致应用程序打印堆栈跟踪:

代码语言:javascript
复制
[INFO ] [2020-10-06 01:49:35.702] [thread=grpc-default-worker-ELG-1-2] [OpID=] [function=connections] [message=Transport failed]
io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2Exception: HTTP/2 client preface string missing or corrupt. Hex dump for received bytes: 0a
    at io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2Exception.connectionError(Http2Exception.java:103) ~[grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.readClientPrefaceString(Http2ConnectionHandler.java:306) ~[grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.decode(Http2ConnectionHandler.java:239) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:438) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:498) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:437) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:792) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:475) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [grpc-netty-shaded-1.31.1.jar!/:1.31.1]
    at java.lang.Thread.run(Thread.java:834) [?:?]

如果客户机和服务器之间存在TLS不匹配(在gRPC意义上)和/或客户机和服务器使用不同的HTTP版本,则会出现此异常。

我认为,在这种情况下,是HTTP版本错配。

有人能帮我解决这个问题吗?还是提出另一种测试Spring应用程序可用性的方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-16 08:32:53

对我来说,诀窍是什么,著名的wait-for-it.sh

在它中,他们使用nc -z命令来测试连接,它不像echo > /dev/tcp/<apps-ip>/8877那样执行connect(2),因此在我的应用程序方面也没有例外。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64349980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档