ejabberd - Comments for "Erlang function integer_to_binary/1 is throwing badargs exception" https://www.ejabberd.im/forum/28580/erlang-function-integertobinary1-throwing-badargs-exception en Hi, Thank you for promply https://www.ejabberd.im/forum/28580/erlang-function-integertobinary1-throwing-badargs-exception#comment-67141 <p>Hi,</p> <p>Thank you for promply addressing the issue.</p> <p>Similar changes need to be made to ejabberd_sql.erl file for this to work.<br /> Have raised pull request for the same if that is of any help: <noindex><a href="https://github.com/processone/ejabberd/pull/1349" title="https://github.com/processone/ejabberd/pull/1349" rel="nofollow" >https://github.com/processone/ejabberd/pull/1349</a></noindex></p> <p>The changes have been verified successfully, locally.</p> <p>Thank you,<br /> Prasad</p> Fri, 21 Oct 2016 08:43:58 +0000 prasadv comment 67141 at https://www.ejabberd.im Since 16.06, the commit https://www.ejabberd.im/forum/28580/erlang-function-integertobinary1-throwing-badargs-exception#comment-67138 <p>Since 16.06, the commit <noindex><a href="https://github.com/processone/ejabberd/commit/d201f013b2e02ee33099df90e20200e718a06c0b#diff-45bfe50eae3f48c669d704891c2543edR697" title="https://github.com/processone/ejabberd/commit/d201f013b2e02ee33099df90e20200e718a06c0b#diff-45bfe50eae3f48c669d704891c2543edR697" rel="nofollow" >https://github.com/processone/ejabberd/commit/d201f013b2e02ee33099df90e2...</a></noindex></p> <p>added this line to node_flat_sql:get_items as you noticed:<br /> SNidx = integer_to_binary(Nidx),</p> <p>That Nidx is get from #pubsub_node.id in mod_pubsub.erl:</p> <pre> get_items(Host, Node) -&gt; Action = fun (#pubsub_node{type = Type, id = Nidx}) -&gt; node_call(Host, Type, get_items, [Nidx, service_jid(Host), none]) </pre><p> and include/pubsub.hrl says that it can be integer or binary:</p> <pre> -type(nodeIdx() :: pos_integer() | binary()). %% @type nodeIdx() = integer() | binary(). %% note: pos_integer() should always be used, but we allow anything else coded %% as binary, so one can have a custom implementation of nodetree with custom %% indexing (see nodetree_virtual). this also allows to use any kind of key for %% indexing nodes, as this can be usefull with external backends such as sql. </pre><p> So, when the value is already a binary, that line crashes, as you reported.</p> <p>I guess the line requires an improvement to handle that the value can already be a binary. There's already a function that checks this, so I committed this fix:<br /> <noindex><a href="https://github.com/processone/ejabberd/commit/2ab72bcd009536a6bef2be04c71470f17e19d0b2" title="https://github.com/processone/ejabberd/commit/2ab72bcd009536a6bef2be04c71470f17e19d0b2" rel="nofollow" >https://github.com/processone/ejabberd/commit/2ab72bcd009536a6bef2be04c7...</a></noindex></p> <p>If you can try it, please confirm it works or not.</p> Thu, 20 Oct 2016 19:58:20 +0000 badlop comment 67138 at https://www.ejabberd.im To further add to this, the https://www.ejabberd.im/forum/28580/erlang-function-integertobinary1-throwing-badargs-exception#comment-67136 <p>To further add to this, the Nidx is already in binary form, so the below line in node_flat_sql.erl in function get_items/3 is causing the issue:</p> <p>SNidx = integer_to_binary(Nidx)</p> <p>Commit for reference:<br /> <noindex><a href="https://github.com/processone/ejabberd/commit/d201f013b2e02ee33099df90e20200e718a06c0b" title="https://github.com/processone/ejabberd/commit/d201f013b2e02ee33099df90e20200e718a06c0b" rel="nofollow" >https://github.com/processone/ejabberd/commit/d201f013b2e02ee33099df90e2...</a></noindex></p> <p>Commenting above line has fixed the issue.</p> <p>Extra Information:<br /> I have upgraded from 16.03 to 16.09.37(non stable release), also running Erlang/OTP 19. Please let me know if this scenario could have caused this issue.</p> <p>Thank you,<br /> Prasad</p> Thu, 20 Oct 2016 10:03:04 +0000 prasadv comment 67136 at https://www.ejabberd.im