impress icon indicating copy to clipboard operation
impress copied to clipboard

Incorrect impress load with Promise.allSettled

Open georgolden opened this issue 2 years ago • 1 comments

Impress and Node.js versions

Node 16, impress 3.0.0-alpha.2

Platform

Linux Fedora latest

Describe the bug

https://github.com/metarhia/impress/blob/ac554b4d6aee02ed920e5d6900c4f8498b240fe3/lib/application.js#L76-L86

There is Promise.allSettled used. API load later and depends on schemas, as it can use Projections or direct references to schemas. If something fails, e.g. with invalid custom type. There will be incorrect state of application server.

https://github.com/metarhia/impress/blob/ac554b4d6aee02ed920e5d6900c4f8498b240fe3/lib/application.js#L91

There must be a potential problems with starter functions as well. Because if error happens we won't know and application can be in a broken state as well.

https://github.com/metarhia/impress/blob/ac554b4d6aee02ed920e5d6900c4f8498b240fe3/lib/application.js#L88

To Reproduce

https://github.com/metarhia/Example/tree/bug/impress-load-allsettled

Expected behavior

I suggest to use Promise.all instead of Promise.allSettled to load impress application and handle errors. If an error during startup occurs, there must be logs and exit 1.

Screenshots

No response

Additional context

No response

georgolden avatar Jul 08 '22 08:07 georgolden

@tshemsedinov I have found a bug

georgolden avatar Jul 09 '22 01:07 georgolden

As of impress 3.01 application stops for your bugged example:

Start: /home/marcus/Metarhia/Example/application
03:41:25  W4   error   TypeError: Cannot read properties of null (reading 'types')
  /node_modules/metaschema/lib/schema.js:42:62
  Array.map (<anonymous>)
  Schema.get types [as types] (/node_modules/metaschema/lib/schema.js:42:47)
  new Preprocessor (/node_modules/metaschema/lib/preprocessor.js:28:23)
  new Schema (/node_modules/metaschema/lib/schema.js:28:26)
  Function.from (/node_modules/metaschema/lib/schema.js:14:12)
  Object.prepare (/node_modules/impress/lib/bus.js:10:37)
  Place.change (/node_modules/impress/lib/place.js:63:41)
  async Place.load (/node_modules/impress/lib/cache.js:22:14)
  async Place.load (/node_modules/impress/lib/cache.js:21:33)
03:41:25  W4   error   Error: Custom type must contain "construct" and "checkType" methods
  checkCustomType (/node_modules/metaschema/lib/types.js:65:11)
  typeFactory (/node_modules/metaschema/lib/types.js:84:5)
  new Model (/node_modules/metaschema/lib/model.js:9:18)
  Object.loadModel (/node_modules/metaschema/lib/loader.js:44:10)
  async Schemas.load (/node_modules/impress/lib/schemas.js:14:18)
03:41:25  W4   error   Can not start worker 4: Error: Can not initialize an Application
  Application.parallel (/node_modules/impress/lib/application.js:77:13)
  async Application.init (/node_modules/impress/lib/application.js:85:5)
  async /node_modules/impress/lib/worker.js:74:3
03:41:25  W4   info    Initialization failed in worker 4
03:41:25  W4   debug   Stop example plugin
03:41:25  W0   info    Can not start Application server

tshemsedinov avatar Jul 31 '23 03:07 tshemsedinov

If start function fails app also exits

tshemsedinov avatar Jul 31 '23 03:07 tshemsedinov