yamada
V2EX  ›  Node.js

write after end 错误

  •  
  •   yamada · Aug 20, 2016 · 3040 views
    This topic created in 3566 days ago, the information mentioned may be changed or developed.

    以下是简化的代码:

    let server = http.createServer(async function (req, res) {
        let req2 = web.request({
                hostname: reqUrl.hostname,
                path: reqUrl.path,
                method: req.method,
                headers: headers,
                agent: false,
            }, function (res2) {
                res.on('error', function (e) { if (e) { console.log(Date() + ':res.error,' + e.message); } err(e, res); });
                res2.on('error', function (e) { if (e) { console.log(Date() + ':res2.error,' + e.message); } err(e, res); });
                res.writeHead(res2.statusCode, res2.statusMessage, res2.headers);
                res2.pipe(res);
            });
            req2.setTimeout(10 * 1000, function (e) { if (e) { console.log(Date() + ':req2.timeout,' + e.message); } err(e, res); });
            req2.on('error', function (e) { if (e) { console.log(Date() + ':req2.error,' + e.message); } err(e, res); });
            req.pipe(req2);
    })
    

    问题是为什么偶尔会出现打印出 res.error,write after end ?

    一般来说 write after end 是在 end 之后继续调用 write 才会触发的错误吧?我这里没有调用任何 end 和 write ,只有 pipe ,是 pipe 内部有错误么?

    3 replies    2016-09-04 00:08:14 +08:00
    meteor
        1
    meteor  
       Aug 20, 2016
    async function (req, res) {}
    是什么用法?
    yamada
        2
    yamada  
    OP
       Aug 20, 2016
    @meteor es7
    mason961125
        3
    mason961125  
       Sep 4, 2016
    一般是没有等回调完成就发送请求。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1156 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 18:13 · PVG 02:13 · LAX 11:13 · JFK 14:13
    ♥ Do have faith in what you're doing.