davidqhr / elixir-captcha

This is a Elixir lib for generating captcha. It drawing captcha image with C code. No dependencies.
MIT License
36 stars 20 forks source link

Captcha.get() can fail due to Port.open message split #3

Open roylez opened 6 years ago

roylez commented 6 years ago

This thing drives me nuts. The same Dockerfile compiles okay locally, but the gives me the following when compiled by CI remotely.

In short, Port.open for some unknown reason could return two messages instead of one.

Erlang/OTP 20 [erts-9.3.3.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:10] [hipe] [kernel-poll:false]             

Interactive Elixir (1.6.6) - press Ctrl+C to exit (type h() ENTER for help)
iex(xxxx@127.0.0.1)3> Port.open({:spawn, Path.join(:code.priv_dir(:captcha), "captcha")}, [:binary])         
#Port<0.7418>
iex(xxxx@127.0.0.1)4> flush                                                                         
{#Port<0.7418>, {:data, "upadm"}}
{#Port<0.7418>,
 {:data,
  <<71, 73, 70, 56, 57, 97, 200, 0, 70, 0, 131, 0, 0, 233, 30, 99, 233, 30, 99,
    233, 30, 99, 233, 30, 99, 233, 30, 99, 233, 30, 99, 233, 30, 99, 233, 30,
    99, 233, 30, 99, 233, 30, 99, 233, 30, 99, ...>>}}
roylez commented 6 years ago

I find System.cmd works with better consistency. It seems to give more reliable output, and internally, it still uses Port.open.

iex(xxxx@127.0.0.1)17> System.cmd(Path.join(:code.priv_dir(:captcha), "captcha"), [])                                    
{<<119, 117, 121, 102, 115, 71, 73, 70, 56, 57, 97, 200, 0, 70, 0, 131, 0, 0,                                                  
   63, 81, 181, 63, 81, 181, 63, 81, 181, 63, 81, 181, 63, 81, 181, 63, 81, 181,                                               
   63, 81, 181, 63, 81, 181, 63, 81, 181, 63, 81, 181, 63, ...>>, 0}  
Sebisnow commented 4 years ago

Will this pull request be accepted or does Port.open work "more reliably" by now?