Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better handling for laggy non-flushing requests

  • Loading branch information...
commit 0aea3490608de8b6089047088d6b96866c2d400f 1 parent c4e2dc1
@isaacs isaacs authored
Showing with 19 additions and 11 deletions.
  1. +19 −11 site.js
View
30 site.js
@@ -24,27 +24,35 @@ function site (req, res) {
// kludge! remove this once we figure out wtf is going on.
var timeout = setTimeout(function () {
+ // don't actually kill it, for now, just log
res.log.error('TIMEOUT! %s', req.url, res._header)
- var er = new Error('Request timed out')
- res.error(500, er)
- setTimeout(function () {
- if (res.connection) res.connection.destroy()
- throw er
- }, 5000)
}, 30*1000) // nothing should take 30s ever.
// maybe the issue is that it's sometimes not flushing?
// flush after 2s, that might make it go away?
- var flusher = setTimeout(function () {
- console.error('flusher!', req.url, res.statusCode, res.headers)
- res._flush()
- }, 2000)
+ var flushes = 0
+ var flusher = setInterval(function () {
+ res.log.warn('flusher!', req.url, res.statusCode, res.headers)
+ flushes++
+ if (flushes < 20) {
+ res._flush()
+ } else {
+ res.log.error('flushing was inadequate', erq.url, res.statusCode)
+ res.socket && res.socket.destroy()
+ clearInterval(flusher)
+ this.close()
+ // ensure that the master finds out about this.
+ setTimeout(function() {
+ process.exit(1)
+ }, 60 * 1000)
+ }
+ }.bind(this), 2000)
res.on('finish', timeoutOk)
res.on('close', timeoutOk)
function timeoutOk () {
clearTimeout(timeout)
- clearTimeout(flusher)
+ clearInterval(flusher)
}
var parsed = url.parse(req.url)
Please sign in to comment.
Something went wrong with that request. Please try again.