cdxem713
V2EX  ›  Node.js

Node Expressjs 里,创建子进程( child_process.fork)报错

  •  
  •   cdxem713 · Sep 2, 2015 · 5681 views
    This topic created in 4080 days ago, the information mentioned may be changed or developed.

    Node Expressjs 里面,用子进程( child_process.fork )执行 js 就会报错,错误信息如下:

    Error: listen EADDRINUSE
    at exports._errnoException (util.js:746:11 )
    at Agent.Server._listen2 (net.js:1156:14 )
    at listen (net.js:1182:10 )
    at Agent.Server.listen (net.js:1267:5 )
    at Object.start (_debugger_agent.js:20:9 )
    at startup (node.js:86:9 )
    at node.js:814:3


    源码:

    POST: process.send ('123');

    var code = req.body.toString ('utf8');
    var crawlerPath = __dirname+'/some/path/test';
    fs.writeFileSync (crawlerPath+'.js',code,'utf8');
    var crawlerProcess = cp.fork (crawlerPath );

    6 replies  •  2016-05-10 20:55:35 +08:00
    Biwood
    Biwood
    Sep 2, 2015
    1
    EADDRINUSE: 给定的地址已经被使用

    不需要说什么了
    cdxem713
    cdxem713
    OP
    Sep 2, 2015
    2
    @Biwood 我知道是端口被占用,但是不知道为什么会被占用
    用 cp.exec ('node '+crawlerPath )没有问题,也可以正确执行,但是 fork 不行,如果需要设置端口,具体是什么参数呢?我在文档里面没有找到详细的说明
    cdxem713
    cdxem713
    OP
    Sep 2, 2015
    3
    @Biwood 好吧。。。刚才发现问题了,我在 WebStorm 里面调试的时候就会报错,正常运行的时候就正常了,估计还是 debug 的原因吧
    Tankpt
    Tankpt
    May 9, 2016
    4
    您好。。问下这个问题你后来是怎么解决的
    cdxem713
    cdxem713
    OP
    May 10, 2016
    5
    @Tankpt 额,是 webstorm debug 的问题,好像和代码没啥关系。直接 run 不会报错
    Tankpt
    Tankpt
    May 10, 2016
    6
    @cdxem713 嗯。。。我这边的话是用了公司的一个框架的问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1374 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:24 · PVG 05:24 · LAX 13:24 · JFK 16:24
    ♥ Do have faith in what you're doing.