You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by Karl Lehenbauer <ka...@flightaware.com> on 2017/05/14 01:45:52 UTC

Tcl random seed in each Apache child can be non-unique when running SeparateVirtualInterps no

This is kind of cool.  If the mod_rivet master interpreter has gotten its random seed initialized, say by some Tcl code requesting a random number, then when Apache forks off children they will inherit the same random seed and hence produce the same sequence.

This can be fixed from the Rivet config by forcing children to re-seed the RNG, something like:

RivetServerConf ChildInitScript "expr {srand([clock clicks] + [pid])}”

It might be a good idea to do this in C in Rivet whenever running SeparateVirtualInterps off.



Re: Tcl random seed in each Apache child can be non-unique when running SeparateVirtualInterps no

Posted by Karl Lehenbauer <ka...@flightaware.com>.

On May 14, 2017, at 11:27 AM, Massimo Manghi <ma...@biol.unipr.it>> wrote:



On 05/14/2017 03:45 AM, Karl Lehenbauer wrote:
This is kind of cool.  If the mod_rivet master interpreter has gotten
its random seed initialized, say by some Tcl code requesting a random
number, then when Apache forks off children they will inherit the same
random seed and hence produce the same sequence.

This can be fixed from the Rivet config by forcing children to re-seed
the RNG, something like:

RivetServerConf ChildInitScript "expr {srand([clock clicks] + [pid])}”

It might be a good idea to do this in C in Rivet whenever running
SeparateVirtualInterps off.



Did you actually try also the case with separate interpreters? In mod_rivet 2.3 these interpreters are slaves of a single root interpreter. How deeply are slave interpreters initialized wrt their parent?

In mod_rivet 3.0 the problem should be confined in the prefork bridge when SeparateVirtualInterps Off, otherwise separate interpreters are interpreters in their own right, not slaves

-- Massimo

Good catch, Massimo...  I had not tried it.  However from the command line it looks like new interpreters are seeded uniquely, even safe interpreters...

 $ tclsh

 % info patchlevel
8.6.6

 % interp create
interp0
 % interp0 eval "expr rand()"
0.06173784474923175

 % interp create
interp1
 % interp1 eval "expr rand()"
0.40116244712898624

 % interp create -safe
interp2
 % interp2 eval "expr rand()"
0.2504010522972797

 % interp create -safe
interp3
 % interp3 eval "expr rand()"
0.27850173519854515


Re: Tcl random seed in each Apache child can be non-unique when running SeparateVirtualInterps no

Posted by Massimo Manghi <ma...@biol.unipr.it>.

On 05/14/2017 03:45 AM, Karl Lehenbauer wrote:
> This is kind of cool.  If the mod_rivet master interpreter has gotten
> its random seed initialized, say by some Tcl code requesting a random
> number, then when Apache forks off children they will inherit the same
> random seed and hence produce the same sequence.
>
> This can be fixed from the Rivet config by forcing children to re-seed
> the RNG, something like:
>
> RivetServerConf ChildInitScript "expr {srand([clock clicks] + [pid])}”
>
> It might be a good idea to do this in C in Rivet whenever running
> SeparateVirtualInterps off.
>
>

Did you actually try also the case with separate interpreters? In 
mod_rivet 2.3 these interpreters are slaves of a single root 
interpreter. How deeply are slave interpreters initialized wrt their 
parent?

In mod_rivet 3.0 the problem should be confined in the prefork bridge 
when SeparateVirtualInterps Off, otherwise separate interpreters are 
interpreters in their own right, not slaves

  -- Massimo

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org