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

Emulator not working with multiple express servers on multiple http triggers across different codebases with --inspect-functions #8067

Open
EthanSK opened this issue Dec 15, 2024 · 5 comments

Comments

@EthanSK
Copy link

EthanSK commented Dec 15, 2024

[REQUIRED] Environment info

firebase-tools: 13.29.1

Platform: macOS

[REQUIRED] Test case

have 2 of these (across 2 codebases, with different names for each (i have api and worker))

import { environment } from '@ai-music-video-studio/worker-config';
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import express from 'express';
import * as admin from 'firebase-admin';
import { onRequest } from 'firebase-functions/https';
import { AppModule } from './app/app.module';
admin.initializeApp();

if (environment.currentEnvironment === 'development') {
  console.log('Using firestore emulator.');
  process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080';
}

const server = express();  

const createNestServer = async (expressInstance: express.Express) => {
  console.log('Creating Worker Nest Server');

  const app = await NestFactory.create(
    AppModule,
    new ExpressAdapter(expressInstance),
  );

  await app.init();
};

// createNestServer(server)
//   .then(() => Logger.log('Nest listening'))
//   .catch((err) => Logger.error('Nest Error', err));

// export const worker = onRequest(
//   { timeoutSeconds: 3600, memory: '8GiB' },
//   server,
// );

export const worker = onRequest(
  { timeoutSeconds: 3600, memory: '8GiB' },
  async (req, res) => {
    await createNestServer(server);
    server(req, res);
  },
);

[REQUIRED] Steps to reproduce

run with --inspect-functions (also using firestore emulator with import and export data, but this isnth relevant)

(my command is this
firebase emulators:start --only functions,firestore --project staging --import=./emulator-export-data --export-on-exit=./emulator-export-data )

[REQUIRED] Expected behavior

functions to work with debugger

[REQUIRED] Actual behavior

doesn't work at all, seems to get stuck or something and stops responding to requests. one of the http servers sometimes works with debugging, but the other one doesnt work at all (the first one sends a request to the second one over http)

it works just fine without inspect-functions, i assume its coz it allows for parallel execution which is related to allowing multiple express instances across codebases for multiple http triggered functions)

(also side-note, watching and refreshing on changes doestn seem to be working under this scenario too, I have to use nodemon)

@aalej
Copy link
Contributor

aalej commented Dec 17, 2024

Hey @EthanSK, thanks for reaching out. I'm working on reproducing this issue, but I'm having some difficulty. To get a better overview of how your functions are set up, and to help us accurately reproduce this error. Could you verify the ff:

  • From what I can gather, you have two different endpoints(for example, api and worker, which exist in their respective codebases). The api endpoint makes a request to the worker endpoint. Is this assumption correct?

  • Does the issue occur when calling the api endpoint? If you call the worker endpoint, does debugger work or does it also get stuck?

Also, are there any errors or warnings raised in the firebase-debug.log you can share with us? Let me know in case I may have misunderstood or missed anything here.

@aalej aalej added the Needs: Author Feedback Issues awaiting author feedback label Dec 17, 2024
@EthanSK
Copy link
Author

EthanSK commented Dec 17, 2024

yes the assumption is correct, but its not necessary to reproduce the bug ( i think)

The issue is hard to reproduce in the same way reliably, its just general buggy behaviour. usually the debugger works for only one of the apps, sometimes not at all, and usually at least one of the apps just doesn't reply to http calls. But it always has at least one of these issues, making the workflow unusable. If i remove --inspect-functions it works fine on both http servers and they both respond to requests as expected

There dont seem to be any errors in the log. just a warning as expected

[warn] ⚠ functions: You are running the Functions emulator in debug mode. This means that functions will execute in sequence rather than in parallel. {"metadata":{"emulator":{"name":"functions"},"message":"You are running the Functions emulator in debug mode. This means that functions will execute in sequence rather than in parallel."}}

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Dec 17, 2024
@EthanSK
Copy link
Author

EthanSK commented Dec 19, 2024

hs_err_pid3494.log
also getting errors like this when running multiple codebases even without inspect-functinos

it gets generated when ctr+c to shut down the emulators. In the terminal it hangs at i logging: Stopping Logging Emulator

@aalej
Copy link
Contributor

aalej commented Dec 20, 2024

Thanks for the additional information. At the moment, I think the issue here might be because when passing the --inspect-funcitons flag, all the functions run in a single process. Since it looks like your functions are running in parallel, with some functions relying on other functions to run, this might be causing the emulator to stall other functions while another function is still running. I'll check this with our engineering team.

Regarding the error from your latest comment. Could you please open up a new report for this as this seems to be a different issue? Looks related to the Firestore emulator.

@EthanSK
Copy link
Author

EthanSK commented Dec 20, 2024

ok, looking forward to the fix, debugging is crucial, and having this multi-codebase setup with proper debugging support can really make firebase a true all in one solution that trumps all else :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants