Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject requests when worker is down #47

Merged
merged 2 commits into from
Oct 12, 2021

Conversation

steve-chavez
Copy link
Member

Helps with #45.

When the worker is down for any reason the request queue will now reject insertions.

-- kill the worker 
-- select pg_terminate_backend((select pid from pg_stat_activity where backend_type = 'pg_net worker'));

select net.http_get('https://github.com');

ERROR:  the pg_net background worker must be up when doing requests
DETAIL:  the pg_net background worker is down due to an internal error and cannot process requests
HINT:  make sure that you didn't modify any of pg_net internal tables or used them for foreign key references

@@ -21,6 +21,25 @@ create table net.http_request_queue(

create index created_idx on net.http_request_queue (created);

create or replace function net._check_worker_is_up() returns trigger as $$
begin
if not exists (select pid from pg_stat_activity where backend_type = 'pg_net worker') then
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforced the condition with SQL.

My original plan was updating a GUC with C in the worker(as mentioned on #44 (comment)), but using the DefineCustomBoolVariable() plus SetConfigOption() didn't seem to work. So I just did it with SQL.

$$ language plpgsql;

create trigger ensure_worker_is_up
after insert on net.http_request_queue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be before insert instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, this is correct 🙏

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in this case we don't care for the NEW/OLD values of the row(or not even the row for that matter) so an AFTER insert should do.

@steve-chavez steve-chavez changed the title Request queue fix Reject requests when worker is down Oct 12, 2021
@steve-chavez steve-chavez merged commit f659a5c into supabase:master Oct 12, 2021
@steve-chavez steve-chavez self-assigned this Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants