[erlang-questions] noproc gen_server cowboy

Björn-Egil Dahlberg egil@REDACTED
Fri May 16 16:43:29 CEST 2014


I thought I would report here whats happening in this particular case.

The problem is the following code:

in $ERL_TOP/erts/emulator/drivers/unix/unix_efile.c:497-502
...
#if SIZEOF_OFF_T == 4
     pInfo->size_high = 0;
#else
     pInfo->size_high = (Uint32)(statbuf.st_size >> 32);  // <- there it is
#endif
     pInfo->size_low = (Uint32)statbuf.st_size;
...

This piece of code expects struct stat.st_size to be of type off_t. I 
don't know if I can count on the man-page being correct when declaring 
that stat st_size is of type off_t? Is it always the correct .. probably 
a bad assumption.

If sizeof(off_t) is 8 (e.g. not 4), this will be executed,

     pInfo->size_high = (Uint32)(statbuf.st_size >> 32)

but if sizeof(statbuf.st_size) is 4 then we have a problem 
sincestatbuf.st_size >> 32 will result in an undefined behaviour.
In this case it will do nothing and happily copy down the value in high.

Hence the 32-bit duplication seen up in the shell from 
file:read_file_info/1.

// Björn-Egil

On 2014-05-14 05:57, Ahmad Baitalmal wrote:
> Björn,
> What kind of arch are you running on?
>
> I'm running on a Ralink RT3052 (MIPS 24KEc V4.12).
>
>
> On Tue, May 13, 2014 at 5:36 PM, Björn-Egil Dahlberg 
> <wallentin.dahlberg@REDACTED <mailto:wallentin.dahlberg@REDACTED>> 
> wrote:
>
>     Oh no .. trouble in paradise.
>
>     I see the same duplication problem here (nice catch Erik),
>
>     1> <<I1:32,I2:32>> = <<15990163246731:64>>, {I1,I2}.
>     {3723,3723}
>
>     Which leads me to think there is a problem in int
>     efile_fileinfo(...) with the highs and lows.
>
>
>
>
>
>
>     2014-05-14 0:02 GMT+02:00 Ahmad Baitalmal <ahmad@REDACTED
>     <mailto:ahmad@REDACTED>>:
>
>         Thanks Erik,
>
>         I did a bit more digging, The call for file:read_file_info in
>         cowboy_static.erl is returning this:
>
>         {ok,{file_info,15990163246731,regular,read_write,
>                        {{2014,5,13},{20,51,46}},
>                        {{2014,5,9},{19,57,47}},
>                        {{2014,5,13},{19,46,18}},
>          33188,1,2049,0,1704124,0,0}}
>
>         The file is only 3723 bytes. I verified this also on an erl
>         shell. Same result.
>
>         So it looks like something is up in kernel-3.0/file.erl when
>         running on a mipsel chip.
>
>         Everything else is working, except for this file size issue.
>         Oh and the body is empty.
>
>         For now, I plan on using an onresponse hook to load up the
>         file and fix the content-length as it goes out. :( Not ideal...
>
>         ______________
>         *Ahmad Baitalmal*
>         *CEO & Co-Founder*
>         *BitBuilder.com <http://BitBuilder.com>*
>         650.539.9401 <tel:650.539.9401>
>
>         On May 13, 2014, at 1:13 AM, Erik Søe Sørensen
>         <eriksoe@REDACTED <mailto:eriksoe@REDACTED>> wrote:
>
>>         It's not just a reverse-endian'ed size...
>>         458453399216374 = 0x'0001'A0F6'0001'A0F6 -- weird duplication...
>>         (0x1A0F6 = 106742 = 104.2KB, so that part fits.)
>>
>>
>>         2014-05-13 1:10 GMT+02:00 Ahmad Baitalmal
>>         <ahmad@REDACTED <mailto:ahmad@REDACTED>>:
>>
>>             Thanks Loïc,
>>
>>             It now runs and I can connect. I thought I read somewhere
>>             that relx automatically started the related apps. I guess
>>             it doesn't always.
>>
>>             There is something wrong still, I'm getting this error
>>             for all files in the browser.
>>             net::ERR_CONTENT_LENGTH_MISMATCH
>>
>>             I checked the headers and cowboy is reporting the header
>>             "*Content-Length:* 458453399216374" for a file that is
>>             only 104K.
>>
>>             Could this be a problem with cowboy running on a
>>             little-endian machine (mipsel)?
>>
>>             Thanks,
>>
>>
>>             On Sun, May 11, 2014 at 10:32 PM, Loïc Hoguin
>>             <essen@REDACTED <mailto:essen@REDACTED>> wrote:
>>
>>                 You didn't start the cowboy dependencies, I'm not
>>                 sure how it could have worked on your Mac. Cowboy
>>                 requires crypto, cowlib and ranch to be started to
>>                 run. Try application:ensure_all_started(cowboy)
>>                 instead and it'll do that for you.
>>
>>
>>                 On 05/12/2014 02:20 AM, Ahmad Baitalmal wrote:
>>
>>                     Hi,
>>                     Im going crazy trying to solve this.
>>
>>                     Works on my Mac, but when I copy to a linux
>>                     router (OpenWRT, R17, cowboy
>>                     0.9.0) it give me the error below.
>>                     Is this a cowboy or erlang gen_server issue?
>>                     I tried http, same result. So it's not an ssl
>>                     issue. I can't tell what
>>                     the error is...
>>
>>
>>                     % --------------------- This is my app code that
>>                     starts cowboy
>>                     -module(onion_app).
>>                     -behavior(application).
>>                     -export([start/2]).
>>                     -export([stop/0]).
>>                     -export([stop/1]).
>>                     -include("common.hrl").
>>
>>                     start(_Type, _Args) ->
>>                      application:start(cowboy),
>>                        Dispatch = cowboy_router:compile([
>>                          {'_', [
>>                            {"/", cowboy_static,   {priv_file, onion
>>                     ,"index.html"}},
>>                      {"/[...]",  cowboy_static,   {priv_dir, onion , ""}}
>>                          ]}
>>                        ]),
>>                        RootDir = code:root_dir(),
>>                        Port = 443,
>>                      cowboy:start_https(my_https_listener, 10,[
>>                            {port, Port},
>>                      {certfile, RootDir ++ "/ssl/onion.crt"},
>>                      {keyfile, RootDir ++ "/ssl/onion.key"}
>>                          ],
>>                          [
>>                            {env, [{dispatch, Dispatch}]}
>>                          ]
>>                        )
>>                      onion_sup:start_link().
>>                     stop(_State) ->
>>                        ok.
>>
>>
>>                     % --------------------- I'm getting this error :(
>>                     Exec: /mnt/sda1/onion/erts-6.0/bin/erlexec -boot
>>                     /mnt/sda1/onion/releases/1/onion -env ERL_LIBS
>>                     /mnt/sda1/onion/releases/1/lib -config
>>                     /mnt/sda1/onion/releases/1/sys.config -args_file
>>                     /mnt/sda1/onion/releases/1/vm.args -- console
>>
>>                     =INFO REPORT==== 11-May-2014::03:45:55 ===
>>                      application: onion
>>                          exited: {bad_return,
>>                     {{onion_app,start,[normal,[]]},
>>                      {'EXIT',
>>                       {noproc,
>>                      {gen_server,call,
>>                     [ranch_sup,
>>                      {start_child,
>>                     {{ranch_listener_sup,my_https_listener},
>>                      {ranch_listener_sup,start_link,
>>                     [my_https_listener,10,ranch_ssl,
>>                      [{port,443},
>>                     {certfile,"/mnt/sda1/onion/ssl/onion.crt"},
>>                     {keyfile,"/mnt/sda1/onion/ssl/onion.key"}],
>>                      cowboy_protocol,
>>                      [{env,
>>                      [{dispatch,
>>                      [{'_',[],
>>                      [{[],[],cowboy_static,
>>                      {priv_file,onion,"index.html"}},
>>                     {[<<"tomato">>,'...'],[],tomato,[tomato]},
>>                       {['...'],
>>                      [],cowboy_static,
>>                      {priv_dir,onion,[]}}]}]}]}]]},
>>                      permanent,5000,supervisor,
>>                      [ranch_listener_sup]}},
>>                      infinity]}}}}}
>>                          type: permanent
>>                     Eshell V6.0  (abort with ^G)
>>                     (onion@REDACTED)1> {"Kernel pid
>>                     terminated",application_controller,"{application_start_failure,onion,{bad_return,{{onion_app,start,[normal,[]]},{'EXIT',{noproc,{gen_server,call,[ranch_sup,{start_child,{{ranch_listener_sup,my_https_listener},{ranch_listener_sup,start_link,[my_https_listener,10,ranch_ssl,[{port,443},{certfile,\"/mnt/sda1/onion/ssl/onion.crt\"},{keyfile,\"/mnt/sda1/onion/ssl/onion.key\"}],cowboy_protocol,[{env,[{dispatch,[{'_',[],[{[],[],cowboy_static,{priv_file,onion,\"index.html\"}},{['...'],[],cowboy_static,{priv_dir,onion,[]}}]}]}]}]]},permanent,5000,supervisor,[ranch_listener_sup]}},infinity]}}}}}}"}
>>
>>
>>                     Thanks,
>>
>>                     --
>>                     Ahmad
>>                     ___________
>>                     650.539.9395 <tel:650.539.9395>
>>
>>                     Sent from my iPhon
>>
>>
>>                     _______________________________________________
>>                     erlang-questions mailing list
>>                     erlang-questions@REDACTED
>>                     <mailto:erlang-questions@REDACTED>
>>                     http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>>                 -- 
>>                 Loïc Hoguin
>>                 http://ninenines.eu <http://ninenines.eu/>
>>
>>
>>
>>
>>             -- 
>>             Ahmad
>>             ___________
>>             650.539.9395 <tel:650.539.9395>
>>
>>             Sent from my iPhone
>>
>>             _______________________________________________
>>             erlang-questions mailing list
>>             erlang-questions@REDACTED
>>             <mailto:erlang-questions@REDACTED>
>>             http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
>
>         _______________________________________________
>         erlang-questions mailing list
>         erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
>         http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
>
>
> -- 
> Ahmad
> ___________
> 650.539.9395
>
> Sent from my iPhone
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140516/6628f2dc/attachment.htm>


More information about the erlang-questions mailing list