title: RabbitMQ as Windows service: badarith error on rpc.erl
body: <p>I am experiencing some problems with RabbitMQ started as a service on Windows.</p>
  
  <ul>
  <li>Operative System: Windows 8 (Microsoft Windows NT version 6.2 Server)
  (build 9200)</li>
  <li>Erlang: R16B03 (erts-5.10.4)</li>
  <li>RabbitMQ: 3.2.2</li>
  </ul>
  
  <p><strong>Goal:</strong> create a RabbitMQ cluster with three servers: Srv1, Srv2, Srv3.</p>
  
  <p>Note: I have carefully followed the official documentation</p>
  
  <p>All the following operations are executed as user "Administrator".</p>
  
  <p><strong>FIRST SCENARIO: start RabbitMQ from command line as a background process</strong></p>
  
  <p>I used the command "rabbitmq-server -detached" on Srv1.
  Result: a file ".erlang.cookie" is created under C:\Users\Administrator
  The execution of the command "rabbimqctl status" is successful and gives me the current state of the node.
  I can then copy the file .erlang.cookie in the same folder on Srv2 and Srv3 and successfully create a cluster.</p>
  
  <p><strong>SECOND SCENARIO: start RabbitMQ as a service (this is requirement I have)</strong></p>
  
  <p>Result: the file ".erlang.cookie" is created under C:\Windows.
  When I type the command "rabbitmqctl status" another file .erlang.cookie is created under C:\Users\Administrator and I receive the following result:</p>
  
  <pre><code>C:\Program Files\Aspect\DashBoard\RabbitMQ\sbin&gt;rabbitmqctl.bat status
  Status of node 'rabbit@RABBITMQ-NODE4' ...
  Error: unable to connect to node 'rabbit@RABBITMQ-NODE4': nodedown
  
  DIAGNOSTICS
  ===========
  
  nodes in question: ['rabbit@RABBITMQ-NODE4']
  
  hosts, their running nodes and ports:
  - RABBITMQ-NODE4: [{rabbit,49428},{rabbitmqctl3045334,49434}]
  
  current node details:
  - node name: 'rabbitmqctl3045334@rabbitmq-node4'
  - home dir: C:\Users\Administrator
  - cookie hash: 0DLAKf8pOVrGC016+6BDBw==
  </code></pre>
  
  <p>We know that this is ok because the two cookies are different.
  So I copy the .erlang.cookie file from C:\Windows into C:\Users\Administrator and I try again the same command. This time I get:</p>
  
  <pre><code>C:\Program Files\Aspect\DashBoard\RabbitMQ\sbin&gt;rabbitmqctl.bat status
  Status of node 'rabbit@RABBITMQ-NODE4' ...
  Error: unable to connect to node 'rabbit@RABBITMQ-NODE4': nodedown
  
  DIAGNOSTICS
  ===========
  
  nodes in question: ['rabbit@RABBITMQ-NODE4']
  
  hosts, their running nodes and ports:
  - RABBITMQ-NODE4: [{rabbitmqctl1178095,49471}]
  
  current node details:
  - node name: 'rabbitmqctl1178095@rabbitmq-node4'
  - home dir: C:\Users\Administrator
  - cookie hash: TIuqp21HOQSoUJT8JfgRQw==
  
  
  C:\Program Files\Aspect\DashBoard\RabbitMQ\sbin&gt;rabbitmqctl.bat status
  Status of node 'rabbit@RABBITMQ-NODE4' ...
  Error: {badarith,[{rabbit_vm,bytes,1,[]},
                    {rabbit_vm,'-mnesia_memory/0-lc$^0/1-0-',1,[]},
                    {rabbit_vm,mnesia_memory,0,[]},
                    {rabbit_vm,memory,0,[]},
                    {rabbit,status,0,[]},
                    {rpc,'-handle_call_call/6-fun-0-',5,
                         [{file,"rpc.erl"},{line,205}]}]}
  </code></pre>
  
  <p>Please notice the Error at the end: "badarith" in rpc.erl, line 205.
  I think that the file is Erlang\lib\kernel-2.16.4\src\rpc.erl
  The function is this one:</p>
  
  <pre><code>handle_call_call(Mod, Fun, Args, Gleader, To, S) -&gt;
      RpcServer = self(),
      %% Spawn not to block the rpc server.
      {Caller,_} =
      erlang:spawn_monitor(
        fun () -&gt;
            set_group_leader(Gleader),
            Reply = 
                %% in case some sucker rex'es 
                %% something that throws
                case catch apply(Mod, Fun, Args) of
                {'EXIT', _} = Exit -&gt;
                    {badrpc, Exit};
                Result -&gt;
                    Result
                end,
            RpcServer ! {self(), {reply, Reply}}
        end),
      {noreply, gb_trees:insert(Caller, To, S)}.
  </code></pre>
  
  <p>and line 205 is 'case catch apply(Mod, Fun, Args) of'</p>
  
  <p><strong>THIRD SCENARIO: start RabbitMQ as a named user to avoid it to create the file .erlang.cookie under C:\Windows</strong></p>
  
  <p>I set the RabbitMQ service to log on as the user "Administrator", this way it does not create the file under C:\Windows but only under C:\User\Administrator.
  Result: when the service starts, the file ".erlang.cookie" is created only under C:\User\Administrator.
  When I type the command "rabbitmqctl status" I get the same error as in the provious case (badarith...).</p>
  
  <p><strong>Now the question:</strong> I have not found any information about this error (badarith).
  Could anyone give me a suggestion about how to troubleshoot/avoid this?</p>