Ticket #35 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

Forked workers all use the same random seed

Reported by: trac Assigned to: asaddi
Priority: major Milestone: flup.server-1.0.2
Component: flup.server Version: 1.0.1
Keywords: Cc:

Description

This came up here: http://code.djangoproject.com/ticket/6648

I use flup to connect django to lighttpd via fastcgi. Upon startup, python seeds the pseudo random number generator to the system time (perhaps?). Using a forked worker model, every forked child process keeps the same seed and generates numbers from that.

Using

random.sample('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 5)

in a view raises the following values:

{{ XDQIU AJMNL JIQXN XDQIU IROXL AJMNL YAPJL CUYOK ODKLA JIQXN WACZR IROXL CYUJE SNQLX YAPJL CUYOK UMOWL ODKLA PIXQG WACZR CYUJE }}}.

The proposal would include re-seeding the pseudo random number generator in every child process directly after forking like this:

random.seed("%d%s" % (os.getpid(), time.ctime()))

Change History

09/26/08 08:05:55 changed by asaddi

  • status changed from new to assigned.

A variation of the proposed fix was committed in 2088903a2175.

The changes involved adding another entropy source (os.urandom(), if available) and using time.time() to get sub-second precision.

Currently untested, I'll resolve the ticket once I (or you, the submitter) can get around to testing the fix.

09/26/08 08:06:46 changed by asaddi

Actually, the actual changeset was 137726cdcd67.

09/26/08 10:32:07 changed by asaddi

  • status changed from assigned to closed.
  • resolution set to fixed.

Fix seems good.