New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRNG :OS does not work in multi-threaded applications on CCL #9

Closed
wnortje opened this Issue Nov 21, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@wnortje
Copy link

wnortje commented Nov 21, 2018

CCL raises error Stream #<BASIC-FILE-BINARY-INPUT-STREAM ("/dev/urandom"/10 ISO-8859-1) #x30200241F31D> is private to #<PROCESS Anonymous thread(78) [Sleep] #x3020022B5D2D> when the OS prng is used in multi-threaded applications, eg inside Hunchentoot request handlers.

See https://ccl.clozure.com/docs/ccl.html#additional-keywords-for-open-and-make-socket

The code below shows the problem when run on CCL

(progn
  (setf ironclad:*PRNG* (ironclad:make-prng :os))
  (bordeaux-threads:make-thread
   (lambda ()
     (format t "Thread1: ~A~%" (ironclad:make-random-salt))
     (sleep 0.1)))

  (bordeaux-threads:make-thread
   (lambda ()
     (format t "Thread2: ~A~%" (ironclad:make-random-salt))
     (sleep 0.1))))

The fortuna prng does work.

Clozure Common Lisp Version 1.12-dev/v1.12-dev.1 (LinuxX8664)
Kubuntu 18.04

@luismbo

This comment has been minimized.

Copy link
Member

luismbo commented Nov 21, 2018

This seems like a CCL feature. Based on a quick inspection, it seems like the prngs aren't thread-safe so you shouldn't be sharing them across threads.

@luismbo luismbo closed this Nov 21, 2018

@wnortje

This comment has been minimized.

Copy link
Author

wnortje commented Nov 22, 2018

Thanks.

This works

(progn
  (bordeaux-threads:make-thread
   (lambda ()
     (let* ((ironclad:*PRNG* (ironclad:make-prng :os)))
       (format t "Thread1: ~A~%" (ironclad:make-random-salt)))))

  (bordeaux-threads:make-thread
   (lambda ()
     (let ((ironclad:*PRNG* (ironclad:make-prng :os)))
       (format t "Thread2: ~A~%" (ironclad:make-random-salt))))))

eadmund pushed a commit to eadmund/ironclad that referenced this issue Feb 14, 2019

Robert A. Uhl
Make *PRNG* be thread-local
Addresses sharplispers#9 & sharplispers#13.

It appears that BORDEAUX-THREADS supports all Lisps which IRONCLAD is
tested under, and so depending on it shouldn't hurt.

Notably, this does _not_ use locking.

eadmund pushed a commit to eadmund/ironclad that referenced this issue Feb 14, 2019

Robert A. Uhl
Make *PRNG* be thread-local
Addresses sharplispers#9 & sharplispers#13.

It appears that BORDEAUX-THREADS supports all Lisps which IRONCLAD is
tested under, and so depending on it shouldn't hurt.

Notably, this does _not_ use locking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment