欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

关于Linux或者Solaris下的随机数读取报错问题【/dev/[u]random closed?】 solarislinuxsunjvm 

程序员文章站 2022-03-23 09:51:59
...
【问题现象】
Apusic启动正常,但是访问web控制台时提示如下错误:
2011-03-17 20:14:32 错误 [apusic.web.default./] 执行Servlet时发生错误。
java.security.ProviderException: nextBytes() failed
        at sun.security.provider.NativePRNG$RandomIO.implNextBytes(NativePRNG.java:287)
        at sun.security.provider.NativePRNG$RandomIO.access$200(NativePRNG.java:125)
        at sun.security.provider.NativePRNG.engineNextBytes(NativePRNG.java:114)
        at java.security.SecureRandom.nextBytes(SecureRandom.java:450)
        at java.util.UUID.randomUUID(UUID.java:178)
        at com.apusic.web.jsp.parser.TreeMaker.assignId(Unknown Source)
        at com.apusic.web.jsp.parser.TreeMaker.processTag(Unknown Source)
        at com.apusic.web.jsp.parser.JspPageParser.parseTag(Unknown Source)
        at com.apusic.web.jsp.parser.JspPageParser.parse(Unknown Source)
        at com.apusic.web.jsp.parser.JspPageParser.parse(Unknown Source)
        at com.apusic.web.jsp.parser.JspParser.parse(Unknown Source)
        at com.apusic.web.jsp.generator.JspCompilationContext.compile(Unknown Source)
        at com.apusic.web.jsp.JspServlet$Page.load(Unknown Source)
        at com.apusic.web.jsp.JspServlet.service(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at com.apusic.web.container.ServletComponent.service(Unknown Source)
        at com.apusic.web.container.WebContainer.invoke(Unknown Source)
        at com.apusic.web.container.RequestDispatcherImpl.forward(Unknown Source)
        at com.apusic.web.servlet.FileServlet.getResource(Unknown Source)
        at com.apusic.web.servlet.FileServlet.doGet(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at com.apusic.web.container.ServletComponent.service(Unknown Source)
        at com.apusic.web.container.WebContainer.invoke(Unknown Source)
        at com.apusic.web.container.WebContainer.processRequest(Unknown Source)
        at com.apusic.web.http.VirtualHost.processRequest(Unknown Source)
        at com.apusic.web.http.HttpServer.processRequest(Unknown Source)
        at com.apusic.web.http.HttpConnectionHandler.service(Unknown Source)
        at com.apusic.web.http.ConnectionHandler.processRequest(Unknown Source)
        at com.apusic.web.http.ConnectionHandler.processConnection(Unknown Source)
        at com.apusic.web.http.ConnectionHandler.run(Unknown Source)
        at com.apusic.util.ThreadPoolImpl$WorkerThread.run(Unknown Source)
Caused by: java.io.EOFException: /dev/[u]random closed?
        at sun.security.provider.NativePRNG$RandomIO.readFully(NativePRNG.java:204)
        at sun.security.provider.NativePRNG$RandomIO.ensureBufferValid(NativePRNG.java:264)
        at sun.security.provider.NativePRNG$RandomIO.implNextBytes(NativePRNG.java:278)
        ... 31 more
【问题分析】
经查阅相关资料并从sun的官网上获取相关信息得知,这可能是sun的一个bug。
【问题解决】
基于目前的情况,解决方式如下,在JVM的启动参数中指定使用的随机数设备,如下:
-Djava.security.egd=file:/dev/./urandom
注意:此处的文件路经中有个dot,而不是/dev/urandom这个格式。
PS:从JDK的源码看,提供的随机数设备的路径分别是:/dev/random和/dev/urandom,但是有时os
也会因为连接错误导致读取随机数设备失败,可以尝试重新删除随机数设备的连接再重新绑定一次,如下:
rm -rf *random
ln -s random
ln -s urandom