thibaultcha / lua-resty-jit-uuid

Fast and dependency-free UUID library for LuaJIT/ngx_lua
http://thibaultcha.github.io/lua-resty-jit-uuid/
MIT License
206 stars 40 forks source link

Same UUID because of Lua cache #12

Closed ozanmuyes closed 7 years ago

ozanmuyes commented 7 years ago

Hi @thibaultcha, thanks for the awesome library.

In the development environment I turn off the Lua cache via lua_code_cache off; directive in the NGINX/OpenResty configuration file. I followed the documentation add the init_worker_by_lua_block block and then use the library to generate UUID v4. I am seeding the generator once in the init_worker_by_lua_block block but if I call uuid() function once (of course local uuid = require "resty.jit-uuid") it returns the same UUID for every time. It doesn't matter if I restart the server or increase worker_processes count, the sequence still the same.

Then I realised the Lua code caching is off. Once turned on UUIDs are random. I just wanted to put it here to heads-up for future users (including myself though). At the end of the day we all know one missing semi-colon may be the cause of all hair-pulling.

Greetings.

thibaultcha commented 7 years ago

Hi!

I just added a note to the README advising users to be weary of the lua_code_cache directive in 2718b295f97b4a3739297a9cae8eebf00bf7bc2b to avoid such confusion going forward. Thanks for sharing your experience!