Open wulftone opened 11 years ago
Thanks for opening this issue, I'll try to get an update in place soon. In the meantime, check the comments http://imperialwicket.com/colosimo-chicago-boss-postgresql-and-bcrypt for some discussion and a few links regarding this issue.
Yeah I looked at all of that and the google groups discussion.. still trying to figure out what all of it means..
From the colosimo directory, does this happen for you:
Terminal:
$ ./init-dev
After ChicagoBoss startup output:
<Enter>
(colosimo@machine)2> bcrypt:hashpw("somePass",bcrypt:gen_salt()).
"$2a$12$WI7Tgxoj/fOrt.00XKwWNumvS0jkc./eB.wcRuyaSN1WrSdrw39fS"
(colosimo@machine)3>
Or do you see an error here?
Yeah, I do:
(colosimo@wulf)1> bcrypt:hashpw("somePass",bcrypt:gen_salt()).
** exception error: no match of right hand side value undefined
in function bcrypt:mechanism/0 (src/bcrypt.erl, line 15)
in call from bcrypt:gen_salt/0 (src/bcrypt.erl, line 18)
However, if I run bcrypt:start().
I get some different things:
(colosimo@wulf)1> bcrypt:start().
ok
(colosimo@wulf)2>
=PROGRESS REPORT==== 28-Nov-2012::19:53:20 ===
supervisor: {local,bcrypt_sup}
started: [{pid,<0.171.0>},
{name,bcrypt_nif_worker},
{mfargs,{bcrypt_nif_worker,start_link,[]}},
{restart_type,permanent},
{shutdown,4294967295},
{child_type,worker}]
=PROGRESS REPORT==== 28-Nov-2012::19:53:20 ===
application: bcrypt
started_at: colosimo@wulf
Then, running the hashpw
again:
(colosimo@wulf)2> bcrypt:hashpw("somePass",bcrypt:gen_salt()).
=ERROR REPORT==== 28-Nov-2012::19:54:20 ===
** Generic server bcrypt_nif_worker terminating
** Last message in was {hashpw,"somePass",
{ok,"$2a$12$YyQJMsn.Cl51g3j3rHGZh."}}
** When Server state == {state,12,<<>>}
** Reason for termination ==
** {function_clause,
[{bcrypt_nif_worker,terminate,
[{badarg,
[{bcrypt_nif,hashpw,
[<<>>,#Ref<0.0.0.5475>,<0.171.0>,"somePass",
{ok,"$2a$12$YyQJMsn.Cl51g3j3rHGZh."}],
[]},
{bcrypt_nif_worker,handle_call,3,
[{file,"src/bcrypt_nif_worker.erl"},{line,42}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,588}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]},
{state,12,<<>>}],
[{file,"src/bcrypt_nif_worker.erl"},{line,34}]},
{gen_server,terminate,6,[{file,"gen_server.erl"},{line,722}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}
** exception exit: {{function_clause,[{bcrypt_nif_worker,terminate,
[{badarg,[{bcrypt_nif,hashpw,
[<<>>,#Ref<0.0.0.5475>,<0.171.0>,"somePass",
{ok,"$2a$12$YyQJMsn.Cl51g3j3rHGZh."}],
[]},
{bcrypt_nif_worker,handle_call,3,
[{file,"src/bcrypt_nif_worker.erl"},{line,42}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,588}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]},
{state,12,<<>>}],
[{file,"src/bcrypt_nif_worker.erl"},{line,34}]},
{gen_server,terminate,6,
[{file,"gen_server.erl"},{line,722}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]},
{gen_server,call,
[bcrypt_nif_worker,
{hashpw,"somePass",{ok,"$2a$12$YyQJMsn.Cl51g3j3rHGZh."}},
infinity]}}
in function gen_server:call/3 (gen_server.erl, line 188)
=CRASH REPORT==== 28-Nov-2012::19:54:20 ===
crasher:
initial call: bcrypt_nif_worker:init/1
pid: <0.171.0>
registered_name: bcrypt_nif_worker
exception exit: {function_clause,
[{bcrypt_nif_worker,terminate,
[{badarg,
[{bcrypt_nif,hashpw,
[<<>>,#Ref<0.0.0.5475>,<0.171.0>,
"somePass",
{ok,"$2a$12$YyQJMsn.Cl51g3j3rHGZh."}],
[]},
{bcrypt_nif_worker,handle_call,3,
[{file,"src/bcrypt_nif_worker.erl"},
{line,42}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,588}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]},
{state,12,<<>>}],
[{file,"src/bcrypt_nif_worker.erl"},{line,34}]},
{gen_server,terminate,6,
[{file,"gen_server.erl"},{line,722}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}
in function gen_server:terminate/6 (gen_server.erl, line 725)
ancestors: [bcrypt_sup,<0.169.0>]
messages: []
links: [<0.170.0>]
dictionary: []
trap_exit: false
status: running
heap_size: 987
stack_size: 24
reductions: 257
neighbours:
=SUPERVISOR REPORT==== 28-Nov-2012::19:54:20 ===
Supervisor: {local,bcrypt_sup}
Context: child_terminated
Reason: {function_clause,
[{bcrypt_nif_worker,terminate,
[{badarg,
[{bcrypt_nif,hashpw,
[<<>>,#Ref<0.0.0.5475>,<0.171.0>,
"somePass",
{ok,"$2a$12$YyQJMsn.Cl51g3j3rHGZh."}],
[]},
{bcrypt_nif_worker,handle_call,3,
[{file,"src/bcrypt_nif_worker.erl"},
{line,42}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,588}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]},
{state,12,<<>>}],
[{file,"src/bcrypt_nif_worker.erl"},{line,34}]},
{gen_server,terminate,6,
[{file,"gen_server.erl"},{line,722}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}
Offender: [{pid,<0.171.0>},
{name,bcrypt_nif_worker},
{mfargs,{bcrypt_nif_worker,start_link,[]}},
{restart_type,permanent},
{shutdown,4294967295},
{child_type,worker}]
=PROGRESS REPORT==== 28-Nov-2012::19:54:20 ===
supervisor: {local,bcrypt_sup}
started: [{pid,<0.175.0>},
{name,bcrypt_nif_worker},
{mfargs,{bcrypt_nif_worker,start_link,[]}},
{restart_type,permanent},
{shutdown,4294967295},
{child_type,worker}]
(colosimo@wulf)3>
Talk about verbose!...
So wherever bcrypt is installed, it's not starting for ChicagoBoss. Also, you'll need to start both crypto and bcrypt:
crypto:start().
bcrypt:start().
Then those errors should go away.
A more fundamental test is just executing 'erl' to bring up the prompt, and trying the same thing. That will tell you if it's a user/environment error, or just a module loading issue for Erlang generically.
I'm also interested in whether or not you installed erlang from a package, or built it from source; and what OS (and architecture) you are using. I know there are a couple of oddities in the Ubuntu Erlang packages, and I'm wondering if they load modules/libs differently than a local ./configure && make && make install would handle them. I'll echo my earlier guess that it's a problem with universal packages and libs stored for 32 or 64 bit specifically.
Hmmm crypto:start().
responds with "already started." The rest is the same as before.
I installed erlang R15B02 with kerl onto Linux Mint 13:
$ uname -a
Linux wulf 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux)
I tried putting erlang-bcrypt
into the ChicagoBoss/deps/
directory, but that didn't seem to accomplish anything in particular...
Also tried putting it in the colosimo.app.src
file, thinking it might autostart (since crypto is in there)... nothing...
{application, colosimo, [
{description, "My Awesome Web Framework"},
{vsn, "0.0.1"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib, crypto, bcrypt, boss]},
{env, []}
]}.
Clearly I need to do lots more reading about this before randomly trying things, hoping they'll work. : )
Is crypto.beam in the same relative location as bcrypt.beam on your system?
[EDIT - 'bcrypt.beam' not 'erlang-bcrypt.beam']
It wasn't, because I moved it into the ChicagoBoss/deps
folder, so I moved it back to .kerl/installs/r15b02/lib/
. That didn't help. However, the comment at the end of your blog post almost worked. : ) I had to change some things to get it to go. I'll fork this and you can see the changes I made in a few minutes here...
This is my super-basic cobbling together of internet information solution: https://github.com/imperialwicket/colosimo/pull/2
It probably sucks. : )
Thanks for figuring this out. I need to figure out how/where to merge this - as it's definitely an environment-specific update.
Meaning you don't have to start bcrypt like this?
Does your bcrypt return something besides a tuple from bcrypt:hashpw()
?
No, I don't start bcrypt at all, it's installed with the rest of my core modules so that whenever I issue 'erl [args]', it loads.
I can call ./init.sh or ./init-dev.sh and the project cloned from master runs, registers, and logs in. But, this is on Debian 32bit, and with a locally built Erlang installation (I've also tested on Amazon Linux, 64bit - again with locally built Erlang).
There are a lot of good reasons for installing bcrypt as a dependency to your project, but in my mind, bcrypt is handy to have at the core level for Erlang. I'm pretty new to Erlang too, and I agree that much of this confusion has to do with loading modules in Erlang generally and the best way to transition this to a CB project.
Nice little intro... but I ran into some problems:
After installing CB, cloning this repo, setting up the db, installing bcrypt (it seems to start in my erl REPL) and making a boss.config file, it still doesn't work.... Here's what I get from the CB log when I try to register a user:
Any clues? I'll gladly update the readme with precise instructions once we get this working. : )