Firebase-functions: Firebase functions:delete does not destroy running instances of the function

Created on 26 Jul 2018  路  5Comments  路  Source: firebase/firebase-functions

Version info

firebase-functions:
2.0.1
firebase-tools:
4.0.0
firebase-admin:
5.11

Test case


https://github.com/firebase/functions-samples/tree/master/typescript-getting-started

Steps to reproduce

Clone the getting started with typescript example, and modify to this code:

'use strict';
import * as functions from 'firebase-functions'

let executions = 0;
export const helloWorld = functions.https.onRequest((request, response) => {
    executions++;
    send(`Hello from Firebase, execution number: ${executions}!\n\n`);
});

Then deploy function, and verify it works by making a GET request.
Then run the delete command: firebase functions:delete helloWorld
The command will successfully delete the function, but the previous instance is still alive. You can verify this by making a GET request, after you delete the function.

Expected behavior

The firebase functions delete command should destroy running instances? Otherwise you get very unpredictable results, when you try to deploy an update to a function and verify it worked.

Actual behavior

The firebase functions delete command does not destroy running instances.

documentation

Most helpful comment

@shrestaz Thanks so much for the detailed repro instructions. I've filed a bug with the internal team that would be able to look into why deployment reports as being done earlier than it actually is done, so that we can fix the problem at the core.

All 5 comments

Thanks for filing, in your experience, how long does the old instance stay for? I assume the GET request stops working after a few minutes?

So I have created a script to measure the time.

First deploy this function:

export const testLongevity = functions.https.onRequest((request, response) => {
    response.send('I am alive!');
    return;
})

Second run this code on your machine. It will:

  1. Deploy the function
  2. Wait 2 seconds, ping it to confirm it's alive
  3. Delete
  4. Keep pinging to see if it's alive, and if not measure duration.
const baseUrl = 'your-base-url';

async function mainScript() {
    try {
        runChildProcess('firebase', ['deploy', '--only', 'functions:testLongevity']);
        await timeout(2000);
        // Wait 2 seconds, and make the function hot!
        let response = await request.get(`${baseUrl}/testLongevity`);
        console.log(`Function is HOT! Response was: ${response}`);
        // Now delete the function!
        runChildProcess('firebase', ['functions:delete', 'testLongevity', '--force']);
        performance.mark('delete_request')
        // Send request to the functions url, until the the response is not "I am alive!"
        while (response.includes('I am alive!')) {
            response = await request.get(`${baseUrl}/testLongevity`);
            await timeout(2000);
        }
        performance.mark('actually_deleted');
        performance.measure('Instance was alive after function deletion for', 'delete_request', 'actually_deleted');
    } catch (error) {
        console.log(`Unexpected error ${error.message}`);
    }
}

mainScript();

Results:
I did a few tests, and the "delay" is in the order of 30-40 seconds.

I hope this can help improve firebase functions developer experience, maybe a temporary solution could be a message to the firebase functions CLI, to warn the user that a delete/operation can take some time to be active.

Or maybe just add a delay of 60 seconds to the relevant :see_no_evil:

@shrestaz Thanks so much for the detailed repro instructions. I've filed a bug with the internal team that would be able to look into why deployment reports as being done earlier than it actually is done, so that we can fix the problem at the core.

Internal bug reference: 74628650

@shrestaz Thanks again for all your help! We've added some extra messaging to firebase deploy to let developers know that functions may take ~30 seconds to go live or to be destroyed. We also are going to continue working on the underlying problem on our backend so that this delay no longer exists. Closing this issue for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TomClarkson picture TomClarkson  路  5Comments

rhodgkins picture rhodgkins  路  5Comments

adrielwerlich picture adrielwerlich  路  4Comments

jspri picture jspri  路  5Comments

soichisumi picture soichisumi  路  6Comments