supabase / pg_net

A PostgreSQL extension that enables asynchronous (non-blocking) HTTP/HTTPS requests with SQL
https://supabase.github.io/pg_net
Apache License 2.0
215 stars 16 forks source link

`net._http_response` rows do not respect TTL #80

Closed steve-chavez closed 1 year ago

steve-chavez commented 1 year ago

Problem

When having a TTL of:

show pg_net.ttl;

6 hours

Doing new requests succeed, but their response rows get deleted quickly(after 1 second):

select net.http_get('https://webhook.site/449fddab-5642-4645-9a5e-6c71f7fe9a8e'); 
select * from net._http_response;
-- 0 rows

This is because the worker inserts rows using a now() default value:

https://github.com/supabase/pg_net/blob/639b0498fd1835a59ab763c2a84a1dfe4c3a21dd/src/worker.c#L339-L340 https://github.com/supabase/pg_net/blob/639b0498fd1835a59ab763c2a84a1dfe4c3a21dd/sql/pg_net.sql#L41

And this now() is not getting updated. Every new insert uses an "old" now() value.

Solution

Use SetCurrentStatementStartTimestamp() before:

https://github.com/supabase/pg_net/blob/639b0498fd1835a59ab763c2a84a1dfe4c3a21dd/src/worker.c#L205-L206

To make now() use the current time.