trailsjs / trailpack-express

:package: Express Trailpack
MIT License
12 stars 15 forks source link

unload can be called before webserver started #55

Closed swarthy closed 7 years ago

swarthy commented 7 years ago

other trailpack initialization can fail and app will stop in this case you will get error

(node:2451) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'close' of null
(node:2451) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
jaumard commented 7 years ago

Hum I think it should wait until the the web server is started and then close it, because here you unload the trailpack without closing the web server, so next time you'll start the project it will complain because port is already used.

swarthy commented 7 years ago

Sorry for my english :) I found this error when get stacked with another issue: when some trailpack throw error due initialize, configure or validate trails stop app (unload all trailpacks) (see https://github.com/trailsjs/trails/blob/master/lib/trailpack.js#L43) (and my trailpack can't handle unload before initialization right way). And if trailpack-express initialize are not called before that moment, then unload will throw TypeError: Cannot read property 'close' of null (nativeServer is not created)

jaumard commented 7 years ago

No problem mine is worse lol I understand the problem, but if initialize is called but nativeServer not created yet we have to wait for it or it will be create after trailpack-express is unload (and block the port). I'll accept this one and open an issue about this. Thanks for this PR :)

swarthy commented 7 years ago

Ah, you are right :) Dont know why I thought that trailpacks sequentially initialized :)