Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Cannot read property _httpMessage of null #1417

Closed
sriramk opened this issue Jul 29, 2011 · 3 comments
Closed

Cannot read property _httpMessage of null #1417

sriramk opened this issue Jul 29, 2011 · 3 comments
Labels

Comments

@sriramk
Copy link

sriramk commented Jul 29, 2011

This seems to be a regression of #836


http.js:705
  if (this.output.length === 0 && this.connection._httpMessage === this) {
                                                 ^
TypeError: Cannot read property '_httpMessage' of null
    at ClientRequest.end (http.js:705:50)
    at IncomingMessage.<anonymous> (/Users/sriramk/code/node-simple-proxy/simple-proxy.js:20:12)
    at IncomingMessage.emit (events.js:88:20)
    at HTTPParser.onMessageComplete (http.js:133:23)
    at Client.onEnd [as onend] (http.js:1553:34)
    at Client._onReadable (net_legacy.js:659:26)
    at IOWatcher.onReadable [as callback] (net_legacy.js:177:10)

Here's some sample code to trigger it

var  http = require('http')
,    sys  = require('sys')
,    fs   = require('fs')

var destination = 'yahoo.com';

http.createServer( function( req, res){

  var proxy =  http.createClient(80, destination);
  var preq = proxy.request( req.method, req.url, req.headers );

  console.log(req.connection.remoteAddress +" "+ req.method +" "+req.url);

  preq.on('response', function (pres){
    console.log("Got response:" + pres.statusCode);
    res.writeHead( pres.statusCode, pres.Headers);
    sys.pump( pres, res );

    pres.on('end',function(){
      preq.end();
      res.end();
    });
  });


  req.on('data',function(chunk){
     preq.write(chunk,'binary');
  });

 req.on('end',function(){
  preq.end();

});

}).listen(8080)
@sriramk
Copy link
Author

sriramk commented Jul 29, 2011

This is on 0.5.2

@koichik
Copy link

koichik commented Jul 29, 2011

This is duplicate of #1223.
The problem is that preq.end() was called twice.

    pres.on('end',function(){
      preq.end();

and

 req.on('end',function(){
  preq.end();

It works if you commented out first preq.end().

This problem does not happen on @mikeal's http client rewrite.
Can we call end() repeatedly?
If so, I will fix this on legacy http module.

@bnoordhuis
Copy link
Member

@koichik

Let's follow http2 behaviour and return false if end() is called more than once. Throwing TypeError is a bug in any case.

I suppose it's as simple as adding a if (this.finished) return false; at the top of OutgoingMessage.prototype.end.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants