yezhihao / netmc Goto Github PK
View Code? Open in Web Editor NEWMVC framework based on netty implementation
License: Apache License 2.0
MVC framework based on netty implementation
License: Apache License 2.0
感谢作者开源如此优秀的代码, 最近使用jt808-server项目时发现一个问题:
服务位于Nginx代理服务之后, Nginx配置如下:
log_format jt '$remote_addr [$time_local] $protocol $status $bytes_received '
'$bytes_sent $upstream_addr';
upstream jt808-server {
server 127.0.0.1:7611;
zone tcp_mem 64k;
}
server {
listen 8851;
proxy_pass 127.0.0.1:7611;
proxy_connect_timeout 1s;
proxy_protocol on;
access_log /var/log/nginx/jt808_access.log jt;
error_log /var/log/nginx/jt808_error.log;
}
Nginx在TCP三次握手之后发出包含proxy header的TCP包在jt808-server的后端服务解码失败, 日志如下:
2022-08-30 21:00:19.518 [808-TCP-4-1] ERROR 消息解码异常[50524f585920544350342031302e352e322e3137392031302e312e312e31333720363435303920383835310d0a7e]
java.lang.NullPointerException: null
at org.yzh.protocol.codec.JTMessageDecoder.decode(JTMessageDecoder.java:69) ~[jtt808-protocol-1.0.0-SNAPSHOT.jar!/:1.0.0-SNAPSHOT]
at org.yzh.protocol.codec.JTMessageDecoder.decode(JTMessageDecoder.java:39) ~[jtt808-protocol-1.0.0-SNAPSHOT.jar!/:1.0.0-SNAPSHOT]
at org.yzh.protocol.codec.JTMessageAdapter.decode(JTMessageAdapter.java:65) ~[jtt808-protocol-1.0.0-SNAPSHOT.jar!/:1.0.0-SNAPSHOT]
at org.yzh.protocol.codec.JTMessageAdapter.decode(JTMessageAdapter.java:19) ~[jtt808-protocol-1.0.0-SNAPSHOT.jar!/:1.0.0-SNAPSHOT]
at io.github.yezhihao.netmc.handler.MessageDecoderWrapper.channelRead(MessageDecoderWrapper.java:36) ~[netmc-3.0.2.jar!/:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.github.yezhihao.netmc.handler.TCPMessageAdapter.channelRead(TCPMessageAdapter.java:42) ~[netmc-3.0.2.jar!/:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:327) ~[netty-codec-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:314) ~[netty-codec-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:435) ~[netty-codec-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:279) ~[netty-codec-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) ~[netty-handler-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496) ~[netty-transport-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:995) ~[netty-common-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.77.Final.jar!/:4.1.77.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.77.Final.jar!/:4.1.77.Final]
at java.lang.Thread.run(Thread.java:750) ~[?:1.8.0_342]
消息50524f585920544350342031302e352e322e3137392031302e312e312e31333720363435303920383835310d0a7e
解码出来为PROXY TCP4 10.5.2.179 10.1.1.137 64509 8851
, 正是proxy_protocol的内容,这也导致Session里获取的RemoteAddress为代理Nginx的地址, 最终的结果就是所有的下行消息发送失败.
根据这篇文章Netty是支持proxy_protocol的, 奈何我Netty不熟, 找不到地方下手, 想请问作者有意向支持吗?
高版本JDK模块拆分后,默认环境中无法找到ParameterizedTypeImpl,导致程序无法正常启动,我使用的JDK17
class io.github.yezhihao.netmc.core.handler.Handler (in unnamed module @0x498d318c) cannot access class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl (in module java.base) because module java.base does not export sun.reflect.generics.reflectiveObjects to unnamed module @0x498d318c
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.