天天看点

tomcat中的Digest严重bug

在web开发中,我遇到了一个很严重的内存泄漏问题,困扰了我一段时间,但经常周折才在HPjmeter的帮助上找到了问题的根源,原来是Digest认证的问题,并且是tomcat的大bug. 现给大家介绍一下,希望大家也能从中受益。

发生问题的类就是DigestAuthenticator.java

里面有这么一句话:

   // Updating the value in the no once hashtable 我个人看,这段代码是tomcat开发人员想处置的一段代码,但可能没有最终用,把这句代码就留下来了,但你可别小看它,它的意思就是往hashtable中加入一条数据,你的web应用如果有大量的digest认证连接就坏了,这段代码会往hashtable加入了很多垃圾数据,但没有代码往外清理,那这就是内存泄漏,我们的同仁说这是内存keep. 解决的办法也很简单就是把这句话注释掉。 

   nOnceTokens.put(nOnceValue, new Long(currentTime + nOnceTimeout));

列出下面tomcat对这个bug的解释(太可气了,人家才说这是p2的bug)

The DigestAuthenticator class contains a small but significant leak. In the

generateNOnce method, the 

nOnceValue is inserted into a Hashtable with an expire time. This feature does

not appear to be fully 

implemented and as a result the Hashtable "nOnceTokens" will continue to grow

un-bounded.

The short term solution to this problem is to remove the Hashtable insert since

it isn't apparently being 

used.

Longer term, the host-expireTime-otherState tuple could be encoded in

client-opaque nOnceValue and 

used across multiple TC5 instances.

本文转自 tianjinhm 51CTO博客,原文链接:http://blog.51cto.com/hanmei/135378

继续阅读