Best practices for the upcoming 1.1.0 release:
- Refer to the
applicationWillStop
event on service to handle the closing logic of the application. service wakanda stop
for Ubuntu and normal kill
for Mac OS ( kill -9
should always be the last resort after some timeout, but this is no longer necessary)
Best practice for current version 1.0.x:
- Prepare the server shutdown using the
HTTP Request Handler
or another method (make sure this is very good and only accept connections from localhost) service wakanda stop
for Ubuntu and normal kill
for Mac OS ( kill -9
should always be the last resort after some timeout, but this is no longer necessary)
More details:
We must distinguish between an HTTP server such as Apache and an application server such as Wakanda Server.
For example, when you use SharedWorker
in Wakanda, you create a separate thread that will run some code. Suppose an employee performs some kind of critical processing of data. If you allow the server to close this worker for you, this can lead to incoherence of data in your application. Therefore, you must process any โlogicalโ business logic by closing it before the server stops the application.
Starting with version 1.1.0, instead of creating a special HTTP Request Handler
, which you can call to prepare for a server shutdown, you can use a service that processes the applicationWillStop
event.
When the server receives a lockable kill signal (TERM, QUIT, INT), it will start the shutdown process (for version 1.1.x for Wakanda Digital App Factory) the following is true:
- Notify each service about
applicationWillStop
event - Notify each service of the
httpServerWillStop
event - Wait until the entire service code is executed - Services are called one at a time (the server waits for the code to process the event that completed its execution before the next service is called) -
- Refuse any new incoming HTTP requests
- Process all HTTP requests in the HTTP server queue
- Ask all workers and threads to execute JS code to stop execution (including request handler code).
- Check if there are any threads / JS Contexts are still active, if so, wait a maximum of 5 seconds.
- The server forces all JavaScript contexts to stop execution and kills all remaining topics
- The server is waiting for threads to close.
- Server is stopping
In versions prior to 1.1.0, the server asks workers to close before notifying services of closing events. Thatโs why we couldnโt rely on services to perform a clean shutdown of SharedWorkers
.
source share