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

Confusing module initialization behavior for hybrid applications #2835

Open
1 task done
jtimmons opened this issue Aug 22, 2023 · 2 comments
Open
1 task done

Confusing module initialization behavior for hybrid applications #2835

jtimmons opened this issue Aug 22, 2023 · 2 comments

Comments

@jtimmons
Copy link
Contributor

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

some of the users of my NestJS gRPC Reflection Module package have reported confusing behavior where the module is not properly initialized when running within their Hybrid Application. The issue boils down to the fact that the app.startAllMicroservices method will start all of the connected microservices and properly serve requests but will not run the module lifecycle hooks. Lifecycle hooks are only run when app.listen is called, however not all users will be running an HTTP server in their application and may omit that

when searching through the issues in this repo it seems like similar confusion has come up before in nestjs/nest#12042 and nestjs/nest#8446. I'm not 100% sure of what solution would make the most sense here so I've added a couple thoughts to start a discussion below

Describe the solution you'd like

the main pitfall here seems to be when a users hybrid application does not use an HTTP server. The Hybrid Application documentation is geared towards a "microservice + HTTP server" scenario, however users may also be running multiple multiple microservices instead without any HTTP server in which case they are not going to use the app.listen call and are not likely to know that they'd need to call app.init manually

Option 1: the simplest solution to this seems like it would be to make the app.startAllMicroservices method run the module lifecycle hooks if they haven't been run already so that the app.listen or app.init calls are no longer necessary. This would also make the microservice startup better match the behavior of the HTTP service startup

Option 2: alternatively we could combine the microservice startup logic into app.listen so that there isn't that distinction in the first place. This would likely require a method override so that the port number wouldn't be required in app.listen

Option 3: we could add a warning to the hybrid application docs to be clear that the app.init or app.listen must be called at some point in the application when using startAllMicroservices

Teachability, documentation, adoption, migration strategy

will update this section after discussion

What is the motivation / use case for changing the behavior?

avoiding confusing scenarios where the application successfully starts up and can serve requests but none of the module lifecycle hooks have run, causing incomplete module configuration

@kamilmysliwiec
Copy link
Member

Option 3: we could add a warning to the hybrid application docs to be clear that the app.init or app.listen must be called at some point in the application when using startAllMicroservices

Let's do this. Would you like to contribute and create a PR to the docs?

@jtimmons
Copy link
Contributor Author

Let's do this. Would you like to contribute and create a PR to the docs?

yeah absolutely, I can put up a PR for it over the next couple days

@kamilmysliwiec kamilmysliwiec transferred this issue from nestjs/nest Aug 25, 2023
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

2 participants