Tick Data Server: C++ UDP "talker" to Nodejs "listener" crashing. Any insight?

Discussion in 'App Development' started by kmiklas, Jun 5, 2017.

  1. kmiklas

    kmiklas

    Attempting to send UDP price ticks from a C++ "talker" process to a nodejs "listener" process, and I'm getting a crash.

    Tick talking and listening is working for C++ to C++ processes. When I added the Nodejs piece listener, it blew up.

    Any insight? Thx, Keith :^)


    TICK DATA: Looks good:

    Code:
        Price unicasted: 49.58
        Price unicasted: 50.00
        Price unicasted: 50.24
        Price unicasted: 50.09
        Price unicasted: 49.81
    C++ TALKER: Working fine.

    Code:
        #define SERVERPORT "4950"
    
        int main(int argc, char *argv[])
        {
            int sockfd;
            struct addrinfo hints, *servinfo;
            int rv;
            size_t numbytes;
            char* address = "192.168.1.100";
      
            memset(&hints, 0, sizeof hints);
            hints.ai_family = AF_INET;
            hints.ai_socktype = SOCK_DGRAM;
            hints.ai_protocol = 0;
      
            if ((rv = getaddrinfo(address, SERVERPORT, &hints, &servinfo)) != 0) {
                fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
                return 1;
            }
            sockfd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol);
      
            char myPrice[7];
            float f;
            while(1) {
                f = randPrice();
                ftoa(f, myPrice, 2); // Convert price to string
                myPrice[5] = '\n'; myPrice[6] = '\0';
      
                std::cout << "Price unicasted: " << myPrice;
                if ((numbytes = sendto(sockfd, myPrice, strlen(myPrice), 0, servinfo->ai_addr, servinfo->ai_addrlen)) == -1) {
                    perror("talker: sendto");
                    exit(1);
                }
                std::this_thread::sleep_for(std::chrono::milliseconds(250));
            }
            freeaddrinfo(servinfo);
            close(sockfd);
      
            return 0;
        }
    NODEJS LISTENER: New addition; crashing.

    Code:
        var PORT = 4950;
        var HOST = '192.168.1.100';
    
        var dgram = require('dgram');
        var server = dgram.createSocket('udp4');
    
        server.on('listening', function () {
            var address = server.address();
            console.log('UDP Server listening on ' + address.address + ":" + address.port);
        });
    
        while(1) {
            server.on('message', function (message, remote) {
                console.log(remote.address + ':' + remote.port +' - ' + message);
            });
        }
    
        server.bind(PORT, HOST);
    ERROR Uh oh!

    Code:
        pickledEgg> node udp.listener.js
        #
        # Fatal error in , line 0
        # API fatal error handler returned after process out of memory
        #
        ==== C stack trace ===============================
        #
        # Fatal error in , line 0
        # API fatal error handler returned after process out of memory
        #
        ==== C stack trace ===============================
        <--- Last few GCs --->
    
        [14801:0x102806800]    13404 ms: Mark-sweep 1385.7 (1425.8) -> 1385.7 (1441.3) MB, 1099.6 / 0.0 ms  allocation failure scavenge might not succeed
        [14801:0x102806800]    14533 ms: Mark-sweep 1400.7 (1441.3) -> 1400.7 (1441.8) MB, 1099.3 / 0.0 ms  allocation failure scavenge might not succeed
        [14801:0x102806800]    15852 ms: Mark-sweep 1401.5 (1441.8) -> 1401.5 (1456.3) MB, 1317.5 / 0.0 ms  allocation failure scavenge might not succeed
    
        <--- JS stacktrace --->
        Cannot get stack trace in GC.
        FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory
         1: node::Abort() [/usr/local/bin/node]
         2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
         3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
         4: v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::AllocateTargetObject(v8::internal::HeapObject*, v8::internal::HeapObject**) [/usr/local/bin/node]
         5: v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject*) [/usr/local/bin/node]
         6: v8::internal::MarkCompactCollector::Evacuator::EvacuatePage(v8::internal::Page*) [/usr/local/bin/node]
         7: v8::internal::PageParallelJob<v8::internal::EvacuationJobTraits>::Task::RunInternal() [/usr/local/bin/node]
         8: v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [/usr/local/bin/node]
         9: v8::internal::MarkCompactCollector::EvacuateNewSpaceAndCandidates() [/usr/local/bin/node]
        10: v8::internal::MarkCompactCollector::CollectGarbage() [/usr/local/bin/node]
        11:     0   node                                0x0000000100bf1593 v8::base::debug::StackTrace::StackTrace() + 19
            1   node                                0x0000000100bee739 V8_Fatal + 233
            2   node                                0x0000000100143e48 v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) + 744
            3   node                                0x00000001005e03bb v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::AllocateTargetObject(v8::internal::HeapObject*, v8::internal::HeapObject**) + 1019
            4   node                                0x00000001005df6be v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject*) + 318
            5   node                                0x00000001005eb8eb v8::internal::MarkCompactCollector::Evacuator::EvacuatePage(v8::internal::Page*) + 235
            6   node                                0x00000001005eb786 v8::internal::PageParallelJob<v8::internal::EvacuationJobTraits>::Task::RunInternal() + 198
            7   node                                0x0000000100b067d9 v8::platform::WorkerThread::Run() + 25
            8   node                                0x0000000100bf3187 v8::base::ThreadEntry(void*) + 87
            9   libsystem_pthread.dylib             0x00007fff9250bc13 _pthread_body + 131
            10  libsystem_pthread.dylib             0x00007fff9250bb90 _pthread_body + 0
            11  libsystem_pthread.dylib             0x00007fff92509375 thread_start + 13
        Illegal instruction: 4
     
    Last edited: Jun 5, 2017
  2. kmiklas

    kmiklas

    Nevermind, I got it.

    In the nodejs section I was setting up an infinite number of 'listener' event handlers. I just needed to set it up once.

    Code:
        while(1) { // <--- HERE, not necessary
            server.on('message', function (message, remote) {
    Nodejs price feed handler successfully receiving market data ticks from the engine!

    Now I need to pipe it out to the world through some form of websocket, so that you can see them in your browser. :fistbump:

    ..but first, I have to set up Cloudflare to defend against DDOS attacks, so that I don't go down the MtGox path. :rolleyes: @Lee- :thumbsup:
     
    Last edited: Jun 5, 2017
    Macca1 likes this.