express-http-proxy icon indicating copy to clipboard operation
express-http-proxy copied to clipboard

Converting circular structure to JSON because of debugger

Open matthieusieben opened this issue 5 years ago • 7 comments

The following line

JSON.stringify(processedReqOpts)

causes a TypeError: Converting circular structure to JSON when defining a custom agent. This is probably due to the internal implementation of require('http').Agent.

You should rather use require('util').inspect instead of JSON.stringify

matthieusieben avatar Nov 07 '18 16:11 matthieusieben

Hi @matthieusieben, thanks for the report, happy to make this update. Can you give me a sample chunk with a custom agent that fails so I can pin this down with a test? Thanks.

monkpow avatar Nov 14 '18 16:11 monkpow

const expressHttpProxy = require('express-http-proxy')

const { Agent: HttpAgent } = require('http')
const httpAgent = new HttpAgent({ keepAlive: true, keepAliveMsecs: 60e3 })

app.use(expressHttpProxy("http://localhost:3000", {
    async proxyReqOptDecorator (proxyReqOpts, userReq) {
      proxyReqOpts.agent = httpAgent
      return proxyReqOpts
    }
})

matthieusieben avatar Nov 14 '18 16:11 matthieusieben

Thanks!

monkpow avatar Nov 14 '18 16:11 monkpow

Huh. So I pushed the following (https://github.com/villadora/express-http-proxy/pull/393) which just has the tests, and I'm having trouble replicating the issue even without the fix applied.

I'm running the tests on CI right now to get information about if its environmentally related. Could you also provide detailed information about your environment? e.g., which version of node, express, debug do you have currently live, and what operating system.

If you don't mind looking at the test to see if you notice any conditions missing, I'd appreciate it. https://github.com/villadora/express-http-proxy/pull/393/files#diff-87ccb5f4d80dd2bb83e08f28ee236c31

monkpow avatar Nov 14 '18 17:11 monkpow

  • Does the proxyTarget "server" respect the keep-alive header and keeps the connection alive ?
  • You may need to run two requests before it fails (so that the agent has one "alive" internal connection)

matthieusieben avatar Nov 14 '18 17:11 matthieusieben

Any news on this? 1.5.0 is not usable with a custom agent option.

matthieusieben avatar Dec 19 '18 16:12 matthieusieben

The proper implementation is actually this one: #400

matthieusieben avatar Jan 11 '19 10:01 matthieusieben