Skip to content

feat: add early shutdown when no requests received for X milliseconds #582

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

Merged
merged 3 commits into from
Aug 12, 2025

Conversation

nyannyacha
Copy link
Contributor

@nyannyacha nyannyacha commented Aug 11, 2025

What kind of change does this PR introduce?

Feature

Description

This PR makes it possible to terminate a worker early if no subsequent response exists for more than X milliseconds from the last request.

You can specify this option when creating the user worker, as shown in the following snippet, and it must be specified in milliseconds:

await EdgeRuntime.userWorkers.create({
  servicePath,
  // ..snip..
  context: {
    supervisor: {
      // If there are no follow-up requests for more than 5 seconds, the user worker is terminated.
      requestAbsentTimeoutMs: 5000,
    }
  }
});

@nyannyacha nyannyacha marked this pull request as ready for review August 11, 2025 22:40
@nyannyacha nyannyacha force-pushed the ny/introduce-req-absent-timeout branch from 56dc063 to 2202845 Compare August 11, 2025 23:19
@nyannyacha nyannyacha changed the title feat: add early shutdown when no requests received for X seconds feat: add early shutdown when no requests received for X milliseconds Aug 12, 2025
@nyannyacha nyannyacha merged commit 64992a9 into develop Aug 12, 2025
5 checks passed
@nyannyacha nyannyacha deleted the ny/introduce-req-absent-timeout branch August 12, 2025 06:43
@farzd
Copy link

farzd commented Aug 19, 2025

Does this have any effect if requestAbsentTimeoutMs is not set? @nyannyacha
My edge functions have started shutting down mid tasks

Screenshot 2025-08-19 at 14 20 02

@laktek
Copy link
Contributor

laktek commented Aug 19, 2025

@farzd Are you using Background tasks to run the function? If so, it wouldn't shutdown early. https://supabase.com/docs/guides/functions/background-tasks

Also from the log events, I cannot see a shutdown event. When a function is shutdown there would be a shutdown log event which shows the reason for shutdown. The early shutdowns will show as "EarlyDrop" as the reason.

@farzd
Copy link

farzd commented Aug 19, 2025

Thanks for the reply @laktek . I'm not using background Tasks.
I have another edge function that returns early and fires off this one. I assumed on Pro plan you get 400 seconds so it would stay alive until that ?

(also please note, i only started having these issues as of recent, wasn't getting early drops before)

image
 [
  {
    "boot_time": null,
    "cpu_time_used": 153,
    "deployment_id": "xxxx",
    "event_type": "Shutdown",
    "execution_id": "aee2c2d4-8beb-484b-90d2-2e572dc0fdb5",
    "function_id": "1a0eb3e7-b021-4f40-b80e-f43ed4e5ba14",
    "level": "log",
    "memory_used": [
      {
        "external": 10811056,
        "heap": 12861832,
        "mem_check_captured": null,
        "total": 23672888
      }
    ],
    "project_ref": "xxxx",
    **"reason": "EarlyDrop",**
    "region": "eu-west-2",
    "served_by": "supabase-edge-runtime-1.68.0-develop.36 (compatible with Deno v2.1.4)",
    "timestamp": "2025-08-19T13:52:20.101Z",
    "version": "18"
  }
]

@laktek
Copy link
Contributor

laktek commented Aug 19, 2025

I'm not using background Tasks.

I assumed on Pro plan you get 400 seconds so it would stay alive until that ?

Pro plan gives you 400s, but if the worker (isolate) becomes idle it'll shutdown. The way we detect if the isolate is idle is by checking if it has pending requests or active background tasks. So if you update your code to run the long-running task as a background task it'll ensure to run for 400s.

(also please note, i only started having these issues as of recent, wasn't getting early drops before)

We always had this behavior, but recently, we refactored the code so it's applied based on the load in each region. This ensures all users get a fair amount of resources, which is probably why you started having these issues recently.

For further support, I'd recommend opening a support ticket.

@farzd
Copy link

farzd commented Aug 20, 2025

Thanks @laktek

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.

3 participants