Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

selenium-server.jar hangs intermittently when getting random session seed #1301

Closed
lukeis opened this issue Mar 2, 2016 · 7 comments
Closed

Comments

@lukeis
Copy link
Member

lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 1301

Run:
$ java -jar selenium-server.jar -debug
13:05:08.489 INFO - Java: Sun Microsystems Inc. 19.0-b06
13:05:08.490 INFO - OS: Linux 2.6.34-gentoo-r12 amd64
13:05:08.495 INFO - v2.0 [b2], with Core v2.0 [b2]
13:05:08.495 INFO - Selenium server running in debug mode.
[...snap...]
12:18:53.685 DEBUG - Starting org.openqa.jetty.jetty.servlet.ServletHandler@4d865b28
12:18:53.686 DEBUG - New random session seed
12:21:27.890 DEBUG - Started holder of class org.openqa.selenium.remote.server.DriverServlet
12:21:27.890 DEBUG - Session scavenger period = 30s
[...snap...]

That's because java's SecureRandom hangs when /dev/random hangs. I don't know why /dev/random
hang. Related code is:
{{{
// remote/server/src/java/org/openqa/jetty/jetty/servlet/AbstractSessionManager.java

    public void start()
    throws Exception
    {
        if (_random==null)
        {
            log.debug("New random session seed");
            try
            {
                _random=SecureRandom.getInstance("SHA1PRNG");
            }
            catch (NoSuchAlgorithmException e)
            {
                log.warn("Could not generate SecureRandom for session-id randomness",e);
                _random=new Random();
                _weakRandom=true;
            }
            _random.setSeed(_random.nextLong()^System.currentTimeMillis()^hashCode()^Runtime.getRuntime().freeMemory());
        }

        if (_sessions==null)
            _sessions=new HashMap();

        // Start the session scavenger if we haven't already
        if (_scavenger == null)
        {
            _scavenger = new SessionScavenger();
            _scavenger.start();
        }
    }
}}}

Solution:
After replace /dev/random with /dev/urandom, selenium works fine:
sudo mv /dev/random /dev/random.real
sudo ln -s /dev/urandom /dev/random

Or you can modify $JAVA_HOME/jre/lib/security/java.security file and changing the property:
securerandom.source=file:/dev/random
to:
securerandom.source=file:/dev/urandom
Maybe it works, but not for me.

Reported by xieyanbo on 2011-02-15 08:37:29

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I'm also seeing this on Windows XP, at exactly the same point in the log.

Reported by tartley on 2011-02-23 15:03:47

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

On a linux box you can typically install something like "randomsound" to increase the
amount of produced entropy. This issue is platform specific and has been worsened by
the use of SSD's, since linux kernels often used variation in platter rotational speed
as one of the sources of entropy.

I've added an entry to the FrequentlyAskedQuestions page about this (Windows XP user
should read this entry), and I'm closing this issue as WontFix

Reported by kristian.rosenvold on 2011-04-13 19:28:44

  • Status changed: WontFix

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Hi,

we just installed selenium server on Ubuntu Server inside a virtual machine (KVM) and
the startup process hangs at the exact same point.

It's a bug when the software reads from /dev/random (which can hang when no new entropy
is generated) rather from /dev/urandom.

Since there is not much HDD activity, no mouse and no keyboard attached the process
will hang all the time.

At least there should be a message to stdout (not only in debug mode) that if the startup
hangs at this point it's due to missing entropy.

It's really shitty to debug this if it's working sometimes (e.g. due to disk activity).

Reported by voodoofoobar on 2014-09-03 10:17:52

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

here some debug excerpt from selenium server startup in debug mode:

13:36:57.513 DEBUG - Starting HttpContext[/wd,/wd]
13:36:57.514 DEBUG - Init classloader from null, sun.misc.Launcher$AppClassLoader@1555aa19
for HttpContext[/wd,/wd]
13:36:57.514 DEBUG - Starting org.openqa.jetty.jetty.servlet.ServletHandler@2ffa1294
13:36:57.514 DEBUG - New random session seed
13:43:32.430 DEBUG - Session scavenger period = 30s
13:43:32.431 DEBUG - Started holder of class org.openqa.selenium.remote.server.DriverServlet
13:43:32.432 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@2ffa1294
13:43:32.433 INFO - Started HttpContext[/wd,/wd]
13:43:32.482 INFO - Started SocketListener on 0.0.0.0:4443
13:43:32.483 INFO - Started org.openqa.jetty.jetty.Server@4671b856

Please pay attention to the time gap between 13:36:57.514 and 13:43:32.430.

At 13:43 i started 'find /` so there was hdd activity.

That's when selenium proceeded.

But java SecureRandom should read from /dev/urandom:

% grep ^securerandom.source /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/security/java.security
securerandom.source=file:/dev/urandom

Any ideas how to get this fixed?

Reported by voodoofoobar on 2014-09-03 12:17:55

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

% strace -o a.strace -f -e file java ....

shows at the bottom of the logfile when selenium blocks the following:

1263  open("/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar", O_RDONLY) = 11
1263  stat("/dev/random", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 8), ...}) = 0
1263  stat("/dev/urandom", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 9), ...}) = 0
1263  open("/dev/random", O_RDONLY)     = 12
1263  open("/dev/urandom", O_RDONLY)    = 13
1263  open("/dev/random", O_RDONLY)     = 14
1263  open("/tmp", O_RDONLY)            = 15
1255  --- SIGINT {si_signo=SIGINT, si_code=SI_KERNEL} ---
1286  open("/dev/null", O_WRONLY)       = 15
1286  +++ exited with 0 +++

Reported by voodoofoobar on 2014-09-03 12:25:22

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Ok folks,

here is my solution.

Despite the fact that 'securerandom.source' in java.security is already configured
like

  securerandom.source=file:/dev/urandom

It seems this doesn't work.

What did work was appending 

  -Djava.security.egd=file:///dev/urandom

to the java binary. This instantly fixes the problem for me on ubuntu trusty with openjdk-7-jre-headless.

Reported by voodoofoobar on 2014-09-03 12:48:29

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 18:11:56

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 2, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant