feature: rebounce support #31

donpdonp opened this Issue Jun 13, 2012 · 1 comment


None yet
2 participants

When a site is down and a bounce fails, I'd like to bounce to a secondary service- an error page.

bouncy(function (req, bounce) {
  var host = req.headers.host;
  if (host.match(/mysite.com$/)) {
    bounce(2200).on('error', function(e) {

The first bounce gives:
Error: connect ECONNREFUSED

The second bounce gives:
for (var i = 0; i < bufs.length; i++) {
TypeError: Cannot read property 'length' of undefined
at /home/donp/frontdoor/node_modules/bouncy/lib/insert_headers.js:17:29
at /home/donp/frontdoor/node_modules/bouncy/index.js:90:9
at Socket. (/home/donp/frontdoor/bouncy.js:18:7)
at Socket.emit (events.js:88:20)
at Array.0 (net.js:301:14)
at EventEmitter._tickCallback (node.js:190:38)

grncdr commented Oct 12, 2012

Hi @donpdonp, in a nutshell: the BufferedStream that bouncy uses (correctly) throws out the buffered chunks the first time the request is piped to a destination. I finally got around to handling this in my proxy diversion today. Take a look at this commit and you can see how I grab a copy of the headers before bouncing, then restore them on each retry. It's more buffer copying than I'd prefer but I didn't want to make any assumptions about how bouncy might munge the buffers in the future.

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