dardoria / uuid

Common Lisp implementation of UUIDs according to RFC4122
47 stars 12 forks source link

Not so random state #2

Closed JesterSks closed 11 years ago

JesterSks commented 11 years ago

I recently used UUID in a compiled project using SBCL and found that the random state does not get changed when the application launches causing repeated v4 UUIDs. The following code recreates the error:

(sb-ext:save-lisp-and-die "uuid-static-random"
    :executable t
    :purify t
    :toplevel (lambda ()
        (unwind-protect
            (format t "uuid: ~A~%" (uuid:print-bytes nil (uuid:make-v4-uuid)))
            (sb-ext:exit))))

I can work around the issue by doing the following:

(sb-ext:save-lisp-and-die "uuid-random"
    :executable t
    :purify t
    :toplevel (lambda ()
        (unwind-protect
            (let ((uuid::*uuid-random-state* (make-random-state t)))
                (format t "uuid: ~A~%" (uuid:print-bytes nil (uuid:make-v4-uuid))))
            (sb-ext:exit))))

Which works but it feels wrong having to violate the implied private nature of uuid-random-state.

tuscland commented 11 years ago

I have reproduced this problem on LispWorks with both hcl:save-image and deliver. Wouldn't it be a solution if *uuid-random-state* was lazily bound at runtime, instead of being initialized as a global variable? This is a pretty serious problem as any delivered application will generate the same UUIDs on each consequent launch.

tuscland commented 11 years ago

Works fine, thanks!

dardoria commented 11 years ago

Thanks for the feedback!