Spring boot 线上环境出现1.2G的sun.security.ssl.SSLSocketImpl对象内存泄漏?

将线上环境的堆转储下来,

jmap -dump:live,file=/root/heap_dump_tce1031.hprof 4455

通过ECLIPSE MAT分析如下:

image.png

系统为微服务,作为服务端只接受http请求,作为客户端通过resttemplate访问外部https服务。求问这种情况怎么解决。google说可以通过配置解决

SSLSocket.getSession().getSessionContext().setSessionCacheSize(0);

但不知道具体怎么配置

阅读 7.3k
1 个回答
新手上路,请多包涵

解决了:
SSLContext sslContext = SSLContext.getInstance("SSL"); //SSL(安全套接字层): Secure Sockets Layer、TLS(传输层安全性): Transport Layer Security 。TLS与SSL在传输层与应用层之间对网络连接进行加密

        /**
         * SSLSocketImpl 内存溢出的原因:
         * Bit late reply but this answer is for future visitors to this question. 
         * The reason that you see large volume of SSLSocketImpl in your heap and then which gets garbage collected is because SSLSessionContext supports caching SSL connections, 
         * which can be reused by across distinct TCP connections to reduce handshake overhead when negotiating temporary encryption keys after the actual TCP connection has been established.
         * By default the SSLSessionContext unlimited number of sessions for default time period of 24 hours, 
         * which means that you can end up using lot of heap memory under high traffic. 
         * One way is to set cache size that suits your application needs. Here is an example: sslContext.getServerSessionContext().setSessionCacheSize(1000);
         */
        sslContext.getServerSessionContext().setSessionCacheSize(0); //
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题