Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • N node-http-proxy
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 482
    • Issues 482
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 102
    • Merge requests 102
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • http ... PARTY!
  • node-http-proxy
  • Issues
  • #1455
Closed
Open
Issue created Jun 09, 2020 by Administrator@rootContributor

Error emitted on proxy server after original request is aborted

Created by: briannielson

I found that for Node 10+ if a request is cancelled before being proxied, the proxyServer emits an error instead of an econnreset event. This does not happen for < Node 8. I believe this is due to a change in the lifetime of error event listeners on the original request socket.

I think the underlying issue is that in lib/http-proxy/passes/web-incoming.js there is an event listener on the aborted event on a request. aborted is a property, I believe the event should be abort. Making this change fixes the issue in my reproduction path.

https://github.com/http-party/node-http-proxy/blob/master/lib/http-proxy/passes/web-incoming.js#L146

Versions:

  • Node 12.16.3
  • http-proxy 1.17.0
  • express 4.17.1

Reproduction path:

  • Open server (source code below)
  • Open a request to the server (I used cURL, you could use your browser) and immediately stop the request
    • curl http://127.0.0.1:8080/echo
  • Observe the following error:
proxyRequest start
proxyRequest Error: socket hang up
    at connResetException (internal/errors.js:608:14)
    at Socket.socketCloseListener (_http_client.js:400:25)
    at Socket.emit (events.js:322:22)
    at TCP.<anonymous> (net.js:672:12) {
  code: 'ECONNRESET'
}

Server code:

var httpProxy = require('http-proxy'),
    express = require('express'),
    http = require('http'),
    httpServer,
    app 
        
function sleep(ms) {
  const date = Date.now()
  let currentDate
  while (!currentDate || currentDate - date < ms) currentDate = Date.now()
}       
      
function proxyRequest(request, response) {
  var proxy = httpProxy.createProxyServer({})

  console.log('proxyRequest start')
  
  proxy.on('proxyReq', (proxyReq, req, res, options) => {
    sleep(5000)
  })
  
  proxy.on('error', err => { 
    console.error('proxyRequest', err)
  })
  
  proxy.web(request, response, { target:'127.0.0.1/demo/api/product' })
}   
    
process.title="test"
app = express()
httpServer = http.createServer(app)
  
app.get('/echo', proxyRequest)
    
app.listen('8080') 
Assignee
Assign to
Time tracking