n8n-io / n8n

Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.
https://n8n.io
Other
50.27k stars 8.14k forks source link

Langchain nodes not respecting HTTP proxy settings #10901

Open rasmusson opened 2 months ago

rasmusson commented 2 months ago

Bug Description

When using a Langchain models like OpenAI and Gemini, HTTP calls going to the models online does not use the HTTP proxy defined for N8N. But go straight to the internet.

I found this as my N8N is not allowed to access internet directly. Allowing direct access resolves the issue

To Reproduce

  1. Setup n8n to use a HTTP proxy using environmental variables HTTP_PROXY and HTTPS_PROXY.
  2. Turn off access to internet except through proxy
  3. Set up and run a simple AI flow using chat trigger, conversational agent and OpenAI model.

Expected behavior

Preferably, the AI model nodes should use the proxy defined for n8n. If not there should be a possibility to configure proxy separately for these nodes

Operating System

Docker

n8n Version

1.59.3

Node.js Version

Provided by docker image

Database

SQLite (default)

Execution mode

main (default)

Joffcom commented 2 months ago

Hey @rasmusson,

We have created an internal ticket to look into this which we will be tracking as "GHC-244"

Joffcom commented 2 months ago

Hey @rasmusson,

I suspect this is not specific to the Langchain nodes and is likely linked to another general issue that we have open where Axios the http package we use doesn't pick up system defined proxies correctly if it is an HTTP proxy due to a failure on the CONNECT method.

rasmusson commented 2 months ago

Ok. As I understand the axios issue resulted in bad gateway error. In my case in the langchain nodes I dont get any error, the request just go straight to internet without going through the proxy. The node works just fine if I allow direct internet access but keep the system defined proxy.

Joffcom commented 2 months ago

Hey @rasmusson,

That sounds a bit different, How are you setting the system proxy? Assuming http_proxy and https_proxy are being set it should still work unless Langchain itself uses an http library that doesn't respect system set proxies.

rasmusson commented 2 months ago

yes, http_proxy and https_proxy env vars. Im using information extractor together with open AI model

Joffcom commented 2 months ago

Perfect, I have moved this to our AI team to investigate. It looks like Langchain may have an issue with proxies.

pemontto commented 1 month ago

Same issue here. Disabling http_proxy and https_proxy on an internet connected host proves the AI nodes fail when it's set. Unfortunately not an option for hosts that require a proxy