fs.sendfile returns ENOMEM on 0.2.4

132 views
Skip to first unread message

Liam

unread,
Oct 27, 2010, 11:35:32 PM10/27/10
to nodejs
Er, maybe it's undocumented for a reason, but I'm trying to implement
a large-file copy function with fs.sendfile, and it's returning ENOMEM
(for a 20kB file). Running 0.2.4 on ubuntu 9.10, and Node's only at
5mB before this...

function dupFile(iSrc, iDst, iCallback) {
fs.stat(iSrc, function(err, stats) {
if (err) { iCallback(err); return; }
fs.open(iSrc, 'r', function(err, infd) {
if (err) { iCallback(err); return; }
fs.open(iDst, 'w', function(err, outfd) {
if (err) { iCallback(err); return; }
fs.sendfile(outfd, infd, 0, stats.size, function(err, sent)
{ ////// err is ENOMEM, sent undefined
fs.close(infd, noOpCallback);
fs.close(outfd, noOpCallback);
if (err || stats.size !== sent) { iCallback(err ||
'sendfile() sent != size'); return; }
child.exec("touch -m -d
'"+stats.mtime.toISOString().replace(/[TZ]/g, ' ')+" UTC' "+iDst,
function(err, stdout, stderr) {
iCallback(err);
});
});
});
});
});
}

Liam

unread,
Oct 27, 2010, 11:42:46 PM10/27/10
to nodejs
The specific error:

.../nodetest.js:167
if (err || stats.size !== sent) { throw err || 'wrongsize';
iCallbac
^
Error: ENOMEM, Cannot allocate memory
at node.js:772:9

mscdex

unread,
Oct 28, 2010, 12:24:38 AM10/28/10
to nodejs
On Oct 27, 11:42 pm, Liam <networkimp...@gmail.com> wrote:
> The specific error:
>
> .../nodetest.js:167
>           if (err || stats.size !== sent) { throw err || 'wrongsize';
> iCallbac
>                                             ^
> Error: ENOMEM, Cannot allocate memory
>     at node.js:772:9
>

I get the same error, but the file is still copied perfectly (on a
~530kb file).

Ben Noordhuis

unread,
Oct 28, 2010, 5:21:58 AM10/28/10
to nod...@googlegroups.com
On Thu, Oct 28, 2010 at 05:35, Liam <networ...@gmail.com> wrote:
> Er, maybe it's undocumented for a reason, but I'm trying to implement
> a large-file copy function with fs.sendfile, and it's returning ENOMEM
> (for a 20kB file). Running 0.2.4 on ubuntu 9.10, and Node's only at
> 5mB before this...

Liam, could you post the output of `uname -a`? How large is the file anyway?

Liam

unread,
Oct 28, 2010, 9:59:34 AM10/28/10
to nodejs
$ uname -a
Linux dell-desktop 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16
14:04:26 UTC 2009 i686 GNU/Linux

stats.size is 19456

mscdex

unread,
Oct 28, 2010, 1:10:54 PM10/28/10
to nodejs
On Oct 28, 9:59 am, Liam <networkimp...@gmail.com> wrote:
> $ uname -a
> Linux dell-desktop 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16
> 14:04:26 UTC 2009 i686 GNU/Linux
>
> stats.size is 19456
>

Just to note, I tried it on both Ubuntu 10.04 x64 and FreeBSD 8.1 x64
with the same result: file is copied but the error is there anyway.

Liam

unread,
Oct 28, 2010, 1:20:21 PM10/28/10
to nodejs
Could it be an eio issue? The code seems to just pass the call thru to
the OS...

Liam

unread,
Oct 28, 2010, 3:18:50 PM10/28/10
to nodejs
eio.c : eio_execute() doesn't test the return value of any call for -1
before using errno!

sendfile(2) mysteriously sets the errno to ENOMEM, but correctly
returns the size written.

Fix:
case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req-
>int2, req->offs, req->size, self);
if (req->result >= 0) errno = 0; break;



On Oct 28, 10:10 am, mscdex <msc...@gmail.com> wrote:

Micheil Smith

unread,
Oct 28, 2010, 3:21:17 PM10/28/10
to nod...@googlegroups.com
Liam:

Could you please email nodej...@googlegroups.com about your findings
on eio_execute / eio.c and sendfile(2).

Thanks,
Micheil Smith
--
BrandedCode.com

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>

Ryan Dahl

unread,
Nov 1, 2010, 11:43:41 AM11/1/10
to nod...@googlegroups.com
On Thu, Oct 28, 2010 at 10:20 AM, Liam <networ...@gmail.com> wrote:
> Could it be an eio issue? The code seems to just pass the call thru to
> the OS...
>

I was handing the error codes in libeio incorrectly. Micheil fixed
this in 98e7d3506f019d396db16a3598437e76ab508922.

Liam, Could you check to see if this commit fixes your problem? (It
should cherry-pick cleanly into the v0.2 branch if you're running
that.)

Reply all
Reply to author
Forward
0 new messages