Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting socket close events on the client. #258

Open
AdamMagaluk opened this issue May 18, 2016 · 1 comment
Open

Detecting socket close events on the client. #258

AdamMagaluk opened this issue May 18, 2016 · 1 comment

Comments

@AdamMagaluk
Copy link
Contributor

I'm using spdy.createAgent method to create a http agent that im reusing for a number of outbound http requests to a server. This is working great but i can't figure out how to handle cases when the tcp connection to the server disconnects after it's been established so i can reconnect and start over.

I can only seem to get the error event on the agent to fire if i start the client when the server if already down. If i start the client with a working server then disconnect the server the client will continue to try and make requests without any errors from either the agent or client request.

Any suggestions?

See example:

var spdy = require('spdy');
var http = require('http');


var agent = spdy.createAgent({
  host: 'localhost',
  port: 1337,

  // Optional SPDY options
  spdy: {
    plain: true,
    ssl: false
  }
}).once('error', function (err) {
  console.log('agent:', err);
});

setInterval(req, 100);

function req() {
  console.log('making req')
  var options = {
    method: 'GET',
    port: 1337,
    agent: agent,
    path: '/'
  };

  var req = http.request(options, function(response) {
    console.log('yikes');
  });

  req.once('error', function(err) {
    console.log('req:', err)
  });

  req.end();
}
@mpech
Copy link

mpech commented Jul 18, 2016

two months later, same pb.
I am considering using

var agent = spdy.createAgent({
...
});

//intuition: once agent is connected, connection is not null but a proper object
agent.on('_connect', function(){
 //we should not be doing this as _spdyState is meant to be an internal to the library...
  agent._spdyState.connection.on('close', function(){
    console.log('closed connection');
  })
})

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

No branches or pull requests

2 participants