Possible issue with writeInt32BE() on ARMv5TE

141 views
Skip to first unread message

Nic Stage

unread,
Jun 29, 2014, 9:53:25 PM6/29/14
to nod...@googlegroups.com

If this is more of an engine.io or socket.io question, I apologize in advance...

I am working on getting nodejs / socket.io / express running on busybox linux on an ARMv5TE processor. I have nodejs up and running and the following code runs without errors.

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

server.listen(80);

app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});

io.on('connection', function (socket) {
    socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
        console.log(data);
    });
}); 

Until I try to connect via websocket from a client. From the browser (with the client script socket.io.jsloaded), var socket = io.connect('ws://192.168.1.8:3000'); or var socket = io.connect('http://192.168.1.8:3000');. Node then logs this error to the console and stops:

buffer.js:784
    throw TypeError('value is out of bounds');

TypeError: value is out of bounds
    at TypeError (<anonymous>)
    at checkInt (buffer.js:784:11)
    at Buffer.writeInt32BE (buffer.js:924:5)
    at Base64Id.generateId (/usr/lib/node_modules/socket.io/node_modules/engine.io/node_modules/base64id/lib/base64id.js:88:8)
    at Server.handshake (/usr/lib/node_modules/socket.io/node_modules/engine.io/lib/server.js:222:21)
    at /usr/lib/node_modules/socket.io/node_modules/engine.io/lib/server.js:184:12
    at Server.checkRequest (/usr/lib/node_modules/socket.io/lib/index.js:67:51)
    at Server.verify (/usr/lib/node_modules/socket.io/node_modules/engine.io/lib/server.js:127:17)
    at Server.handleRequest (/usr/lib/node_modules/socket.io/node_modules/engine.io/lib/server.js:174:8)
    at Server.<anonymous> (/usr/lib/node_modules/socket.io/node_modules/engine.io/lib/server.js:362:12)

Running the same node server from my desktop computer (Windows 8 64 bit), does not produce this error.

I can trace the error to these lines of code in node_modules/socket.io/node_modules/engine.io/node_modules/base64id/lib/base64id.js:

Base64Id.prototype.generateId = function () {
    var rand = new Buffer(15); // multiple of 3 for base64
    if (!rand.writeInt32BE) {
        return Math.abs(Math.random() * Math.random() * Date.now() | 0).toString() + Math.abs(Math.random() * Math.random() * Date.now() | 0).toString();
    }
this.sequenceNumber = (this.sequenceNumber + 1) | 0;
rand.writeInt32BE(this.sequenceNumber, 11);
...

If I change rand.writeInt32BE(this.sequenceNumber, 11); to rand.writeInt32BE(this.sequenceNumber, 11, true);, the error goes away and I can continue on without problems (presumably). So:

  • Why does this error occur when running my code from the ARMv5TE machine?
  • Is my change to base64id.js safe or appropriate?

Jimb Esser

unread,
Jun 30, 2014, 2:22:52 PM6/30/14
to nod...@googlegroups.com
Adding that "true" only tells the Buffer module to skip the assert, which is telling you about what is probably a legitimate problem.  It looks like on that platform ((undefined + 1) | 0) is ending up as NaN instead of 0. Try adding proper initialization to the Base64Id constructor and see if this fixes it:
var Base64Id = function() {
this.sequenceNumber = -1;
};
If so, that sounds like a V8 bug on that platform (should be simple to reproduce on the console by executing "((undefined + 1) | 0)" and see if it gets anything other than the integer 0).
<ul style="margin: 0px 0px 1em 30px; padding: 0px; border: 0px; font-size: 14px; vertical-align: baseline; list-style-position: initial; list-style-image: initial; color: rgb(0, 0, 0); font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 1
...

Nic Stage

unread,
Jun 30, 2014, 3:25:34 PM6/30/14
to nod...@googlegroups.com
Thanks for your reply! Initializing this.sequenceNumber, like so:

var Base64Id = function() {
this.sequenceNumber = -1;
};

results in the same error (buffer.js:784 "Value is out of bounds"). I console.log this.sequence number just before the call to writeInt32BE():

this.sequenceNumber = (this.sequenceNumber + 1) | 0;
console.log(rand, this.sequenceNumber);
rand.writeInt32BE(this.sequenceNumber, 11);

and I get this on the console:

<Buffer 08 dd 51 00 00 00 00 00 00 00 00 00 00 00 00> 0

So the bitwise operator is doing what I'd expect and resulting in 0. The buffer looks like a normal buffer of 15 length, as expected, so I don't understand why rand.writeInt32BE(this.sequenceNumber, 11) is resulting this error. It must be some quirk of nodejs / V8 on this particular architecture.

Here is another complete oddity (to me), that may be a clue. On the ARM machine, if I run this code:

var x = new Buffer('0000000000');
console.log(x);
x.writeInt32BE(0x00, 0);
console.log(x);

I get the result:

<Buffer 30 30 30 30 30 30 30 30 30 30> <Buffer 00 00 00 00 30 30 30 30 30 30>

But if I change the code to simply log the length of the buffer (instead of the buffer itself) before calling writeInt32BE():

var x = new Buffer('0000000000');
console.log(x.length);
x.writeInt32BE(0x00, 0);
console.log(x);

It crashes the same error (buffer.js:784 "value is out of bounds"). Basically, if I change the second line to log anything but x, it will crash.

Jimb Esser

unread,
Jul 1, 2014, 1:14:55 PM7/1/14
to nod...@googlegroups.com
That is very strange indeed.  Unless you're on a very different version of node than the code I'm looking at, the code path from Buffer.writeInt32BE() to the point where it throws the assertion does not even reference the buffer itself, it's just comparing the passed in value to some constants.  If a previous log statement (which, also, should not be making any changes to any state) is changing that behavior, that's very bizzare.  Exactly what version of node (run node --version) are you testing this on?  Any other system instability on that device, have you tried running a memory test in case there is a hardware issue?

Nathan Rajlich

unread,
Jul 1, 2014, 7:50:54 PM7/1/14
to nodejs
This sounds like a genuine bug in Node.js / V8. Can you open an issue on the Node.js Issue tracker so that we can look into this further?

Also, what version of Node.js are you using?


--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/f428d421-bd4d-4031-878e-6e6cc89195ca%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nic Stage

unread,
Jul 1, 2014, 10:40:11 PM7/1/14
to nod...@googlegroups.com
I will try to run some hardware tests. Some specifics: This is busybox linux version 1.22.1. nodejs is v0.10.12 (eek!). Hardware is a Marvell Kirkwood 6281 (Feroceon) ARMv5TE and memory is 256MB. No history of memory problems in my experience. I ran some memory tests with dd and md5sum and everything seemed ok. This environment was built using buildroot and v0.10.12 of nodejs is just the version that buildroot has. I know I can't go past a certain of nodejs because V8 support was dropped for ARMv5TE at some point.

    }<span s
...

Nic Stage

unread,
Jul 1, 2014, 10:40:59 PM7/1/14
to nod...@googlegroups.com
Since I can't get up to the most recent version of nodejs (see above post) and I'm on v0.10.12 is it still worth posting an issue?
this.sequenceNumber = (this.sequenceNumber + 1</
...
Reply all
Reply to author
Forward
0 new messages