Can't send HTTP requests to localhost from a trigger function
HTMHell opened this issue · comments
Bug report
Describe the bug
When trying to send a request from a trigger function, the request doesn't reach the server. In the _http_response
table, the error message is:
Couldn't connect to server
To Reproduce
Do the following locally:
- Create an edge function, and serve it.
- Create a trigger function that makes an HTTP request to your edge function:
begin
perform
net.http_post(
url:='url_to_your_localhost_edge_function',
body:='{}'::jsonb
) as request_id;
return new;
end;
- Create a trigger that will execute the function
- Trigger the function
- You will notice the request did not reach the edge function.
Expected behavior
The request should go through.
Additional context
- I tried to use both 54321 and 8000 ports
- When I
curl
my edge function, it works - When I use an external URL instead of localhost, it works
System information
- OS: macOS
When trying to send a request from a trigger function, the request doesn't reach the server. In the _http_response table, the error message is:
Couldn't connect to server
Hm, this looks more of an infra issue since pg_net is reporting the error correctly.
This seems related supabase/supabase#9837
@HTMHell Could you try reaching your edge function with pgsql-http?
This seems related supabase/supabase#9837
Yep, this is unfortunately due to localhost
mapping to the Postgres container itself - to reach the Docker host (and all ports exposed on it), either host.docker.internal
or 172.17.0.1
have to be used as the target hostname.
@HTMHell could you try using any of the above options to confirm that the http request connects as expected?
This seems related supabase/supabase#9837
Yep, this is unfortunately due to
localhost
mapping to the Postgres container itself - to reach the Docker host (and all ports exposed on it), eitherhost.docker.internal
or172.17.0.1
have to be used as the target hostname.@HTMHell could you try using any of the above options to confirm that the http request connects as expected?
Yup, that did the trick. Thank you!