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

feat(core): Add app.teardown functionality #2570

Merged
merged 2 commits into from
Mar 28, 2022

Conversation

idaho
Copy link
Contributor

@idaho idaho commented Mar 4, 2022

This feature is about to shut down the application and run teardown functionalities after the http server is closed on each service.

In some cases, e.g. when we stop/restart the Node application, the connections to various databases are not closed properly and remain open until the system closes these open connections after some time.

As a counterpart to app.listen() there is now the method app.close() which closes the http server and then calls the teardown methods of the individual services.

In this way, logic for teardown can also be implemented as in the setup methods of the services.

import app from './app';

const server = await app.listen(1234);

const close = async (): Promise<void> => {
  await app.close();
  process.exit(1);
};

process.on('SIGINT', close);
process.on('SIGTERM', close);

As I even saw in PR #2510, it would even be a good idea to implement an addTeardown method where we can configure the logic to happen at the application level.

@daffl daffl changed the title feat: create teardown functionality feat(core): Add app.teardown functionality Mar 28, 2022
@daffl daffl merged commit fcdf524 into feathersjs:dove Mar 28, 2022
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.

2 participants