C
C
cat_crash2012-11-01 18:20:29
PHP
cat_crash, 2012-11-01 18:20:29

NodeJS+DNode+Php - error Error: write EPIPE?

Good day.
Once again I struggle with incomprehensible moments for me in nodeJs. Now I've encountered an error that again I can't solve on my own and I'm asking for the community's help:
I'm writing a PHP application and decided to transfer some functionality to NodeJS in view of its performance, flexibility and easy scalability.
So what is:
- RPC Server on NodeJS. Communication with PHP is organized through the DNode module which exists for both languages. But PHP while I plan to use as the client.
So NodeJS side:

require('epipebomb')()
require('./includes/array.js')
var dnode  = require('dnode')
var net = require('net')
var request = require('request')
var tidy = require('tidy2')
var util = require('util')
var dom = require('xmldom').DOMParser

var server = net.createServer(function (c) {
  var d = dnode({

  
    mul: function (requestUrl,fields,callback){
            request(requestUrl, function (error, response, body) {
            console.log('Fetch url:'+requestUrl);
              
              if (!error && response.statusCode == 200) {
                  
                  var html=tidy.tidyString(body)
                  var doc = new dom().parseFromString(html)									

                  for ( var key in fields ) {
                  
                    var subfields = fields[key]
                    
                    for(var subkey in subfields){
                    
                      console.log(subfields[subkey])
                      //Include extensions for processing 
                      require('./includes/'+subfields[subkey]+'.include.js')
                      global[subfields[subkey]](subkey,doc,requestUrl);

                    }
                    //Dummy
                    var array
                    callback(array);
                  

                  }

              }
            
            })
          }
    })
    c.pipe(d).pipe(c);
});
server.listen(5050)

and accordingly the PHP side to call:
public function run($args){
    require_once "extensions/DNode/DNode.php";
    
    $dnode = new \DnodeSyncClient\Dnode();
    $connection = $dnode->connect('localhost', 5050);
    
    
    $fields=Fields::model()->findAll();
    
    foreach($fields as $field){
        $js_field[$field->name]=array($field->path=>$field->function);
    }
    
    $pages=Pages::model()->findAll();
    
    
    foreach($pages as $page){	
          
      $response = $connection->call('mul', array($page->url,$js_field));
      var_dump($response);
      
      
    }
    
  }

After several days of searching for the reason, I came to the conclusion that the error occurs only when I wrap everything in Dnode. Those. if you manually set arrays in Nodejs that should come from PHP, then there is no error. If I wrap it in a remote procedure, then Noda throws an error
stream.js:81
      throw er; // Unhandled stream error in pipe.
            ^
Error: write EPIPE
    at errnoException (net.js:769:11)
    at Object.afterWrite (net.js:593:19)

I tried to search, but many refer to epipebomb. Installing it does not solve the problem.
Theoretically, I imagine that the problem most likely arises from the desynchronization of threads, and DNode is most likely designed for one thread (Request-Response)
In general, the question is simple - who has come across a bunch of NodeJS + Php + Dnode and how to make them work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wickedweasel, 2012-11-01
@cat_crash

github.com/mhart/epipebomb#notes
epipebomb catches only those errors that are caused by console EPIPEs
In general, this is most likely a bug in the dnode itself, for some reason it tries to write to a socket that can no longer be written to. There even already is a bug on this topic: github.com/substack/dnode/issues/107
I recently fixed these errors in axon'e .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question