Skip to content
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

GENERATE-RANDOM-ID: The value -1 is not of type (UNSIGNED-BYTE 64) #81

Closed
daninus14 opened this issue Jan 8, 2024 · 5 comments
Closed

Comments

@daninus14
Copy link
Contributor

I am getting the following error:

The value -1 is not of type (UNSIGNED-BYTE 64)

Here's the stacktrace:

Backtrace for: #<SB-THREAD:THREAD "hunchentoot-worker-127.0.0.1:58169" RUNNING {1001172B03}>
0: (CL-ISAAC:RAND64 #S(CL-ISAAC:ISAAC64-CTX :RANDCNT 0 :RANDRSL #(3925593177097861953 9711298613570277120 13301789079780403768 5851447409938752469 7395316721195156215 3876317782763891039 17324142642302461745 5173381862221173775 2232769689812699852 641431748002290388 7852246810531221939 12946534270186310260 ...) :RANDMEM #(15932170542592125262 5641653233185709706 17469926063756623801 18436779483168812525 6140313674221961030 10760809802976968553 8867473602531037886 4928843196377889572 17910188103990029047 6963694444940152626 13295689543317008908 3498414824101057605 ...) :A 14509949935736105173 :B 10253657088000355703 :C 1025))
1: (CL-ISAAC:RAND-BITS-64 #S(CL-ISAAC:ISAAC64-CTX :RANDCNT 0 :RANDRSL #(3925593177097861953 9711298613570277120 13301789079780403768 5851447409938752469 7395316721195156215 3876317782763891039 17324142642302461745 5173381862221173775 2232769689812699852 641431748002290388 7852246810531221939 12946534270186310260 ...) :RANDMEM #(15932170542592125262 5641653233185709706 17469926063756623801 18436779483168812525 6140313674221961030 10760809802976968553 8867473602531037886 4928843196377889572 17910188103990029047 6963694444940152626 13295689543317008908 3498414824101057605 ...) :A 14509949935736105173 :B 10253657088000355703 :C 1025) 160)
2: (LACK.UTIL:GENERATE-RANDOM-ID)

I wasn't getting the error before. Not sure if it's because of an update.

Any ideas on what I can do?

@daninus14
Copy link
Contributor Author

It looks like this is the culprit: GENERATE-RANDOM-ID

@daninus14
Copy link
Contributor Author

Update: I think this is a problem with the seed and the underlying library used for generating the random numbers.

To reproduce the problem:

(let ((ctx (isaac:init-self-seed :count 5 :is64 T)))
  (dotimes (n 100) (isaac:rand-bits-64 ctx 160)))

So since lack.util is using isaac, it's causing a problem after a number of random numbers generated.

Doing this:

(let ((ctx (isaac:init-self-seed :count 5 :is64 T)))
  (dotimes (n 100)
    (format T "~A: ~A~%" n (isaac:rand-bits-64 ctx 160))))

I seem to consistently get an issue after 84 runs.

I will check the cl-isaac docs, however, this is an issue in ningle itself for relying on this library with an issue.

Can you please fix this?

  • We could replace the generator?
  • We could provide a new seed after every 80 runs (an ugly hack)

By the way, is this thread safe? Since ningle is using threads, we should be concerned as well. I haven't tested for issues with thread safety, but another thing to think about.

What are your thoughts?

@svetlyak40wt
Copy link
Contributor

I've figured out that cl-isaac's context is not thread-safe. Thus generate-random-id should wrap the call to cl-isaac into the bt2:with-lock.

@daninus14
Copy link
Contributor Author

@svetlyak40wt thanks for checking that!

Update: @svetlyak40wt also fixed the underlying bug in the cl-isaac library, however, it looks like the maintainer is not active in github so he hasn't accepted the pull-request. Because of that, unless one is using qlot and specifying the fork, or downloading to local-projects in quicklisp, this project (lack) is broken for depending on cl-isaac.

Summary of What Needs To Get Done:

  • For Seed issues we need to either:
    • Change the number generator to a non-broken library
    • Or redefine (defun cl-isaac:rand64) and (defun cl-isaac:rand32) like the changes in the pull-request from @svetlyak40wt
    • Or get @thephoeron to accept the pull request
  • If staying with the cl-isaac library: wrap the call to the random number generator with the seed variable with a lock to avoid threat safety issues. If the library is changed, it must be verified the usage of the new library is thread safe

In the meantime I'll send an email to @thephoeron to see if he can accept the PR.

@daninus14
Copy link
Contributor Author

Closing this since PR #82 has been merged. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants