Tytan888 / CSSWENG-S11-G1

0 stars 0 forks source link

Singleton Duplicate Error #2

Closed rpineda26 closed 11 months ago

rpineda26 commented 11 months ago

💾 Description: The singleton model contains the vision, mission, and other general details about the client organization. There is supposed to be only one instance of the model. An error occurs when the server is started from scratch where there is no singleton instance created yet in the database. Upon loading the home page for the first time, the first instance of the singleton is created. An error occurs immediately indicating another request to create the singleton was made alongside the first request. The first singleton is retained in the database and the server can be restarted successfully without the bug reoccurring after the first start up.

image

⏰ Expected Outcome: The server should successfully run in the first start-up without crashing because of the singleton. There should only ever be one request to create a singleton if it doesn't already exist.

☎️ Actual Outcome: Multiple requests to create the singleton are processed during the first launch of the web app leading to the server crashing.

🎶 Steps to Reproduce

  1. Delete the existing database or connect to a new one by changing the database URL. It is also possible to drop only the singleton collection instead of the whole database.

    image
  2. Run npm start.js to start the server and go to the website. Make sure not to user scripts that automatically restarts the server after crash like nodemon or supervisor. Open the webapp in the browser.

    image
  3. Notice in the terminal that the server has crashed (refer to the first screen shot above). Check the database, a singleton instance should be stored.

    image
  4. Restart the server and it should be working correctly.

    image
rpineda26 commented 11 months ago

🛠️ Fix: The bug was related to the method's asynchronous nature, resulting in multiple requests to create a singleton instance. The await word was not written in asynchronous calls and the wrong method (getFooter) was called inside getIndex in the singleton_controller.js file.

image

New Output/Behavior: The server now does not crash on the very first setup with a clean-slate database.