Skip to content

Running a program which accepts stdin/stdout in Node.js causes it to consume 100% CPU+RAM  #1151

@shlomif

Description

@shlomif

Hi,

I am trying to build perl5 using emscripten and so far I have this:

https://github.com/shlomif/perl5-build-using-emscripten

However I'm running into problem with the perl "tryp.c" example, and could not find anything in a web search.

Please run the following script in an empty directory with "emcc" and "node" (from node-js) in the path:

#!/bin/bash

cat <<EOF > tryp.c
#include <stdio.h>
int
main(int argc, char **argv)
{
    char buf[1024];
    int i;
    char *bp = buf;
    while (1) {
    while ((i = getc(stdin)) != -1
           && (*bp++ = i) != '\n'
           && bp < &buf[1024])
    /* DO NOTHING */ ;
    *bp = '\0';
    fprintf(stdout, "%s", buf);
    fflush(stdin);
    if (i == -1)
        return 0;
    bp = buf;
    }
}
EOF

emcc --jcache -s TOTAL_MEMORY=134217728 -std=gnu99 -O2 -I . -m32 -o tryp.js tryp.c
node tryp.js

node ends up consuming 100% of CPU and gradually consumes more and more RAM. Can this be fixed?

Update: I am on Mageia Linux 3 Cauldron ( http://www.mageia.org/en/ ) with clang-3.2-5.mga3 , llvm-3.2-5.mga3 , nodejs-0.10.3-2.mga3 , etc.

Thanks!

-- @shlomif

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions