firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

streaming callable API: client aborted stream -> how to know on server?

Open Obiwarn opened this issue 7 months ago • 5 comments

I am testing the new streaming API for cloud functions in emulator. Aborting streams with an AbortController on my client works fine.

How can the called function know that the user canceled the stream? The CallableResponse signal does not fire an event.

I want to pass an abort signal to the AI API I am calling in the function.

export const aiStreamText = onCall<AiStreamTextRequest>(
  async (request, response) => {
    response?.signal.addEventListener("abort", () => {
      console.log(new Date().toISOString(), "on server: aborted by user");  // THIS DOES NOT FIRE ON ABORT
    });

Related issues

[REQUIRED] Version info

node:

firebase-functions:

firebase-tools:

firebase-admin:

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

[REQUIRED] Expected behavior

[REQUIRED] Actual behavior

Were you able to successfully deploy your functions?

Obiwarn avatar Mar 26 '25 10:03 Obiwarn