mesg-foundation / js-sdk

Javascript mono-repo with all the tools to interact with MESG
https://mesg.com
4 stars 4 forks source link

When the command `service:dev` throws an error, the engine is not stopped and the next use of `service:dev` doesn't stop the engine and the running service: #201

Closed antho1404 closed 4 years ago

antho1404 commented 4 years ago

When the command service:dev throws an error, the engine is not stopped and the next use of service:dev doesn't stop the engine and the running service:

➜  js-sdk git:(bug/config-path) ./packages/cli/bin/run service:dev ../services/service-ethereum
  ✔ Start environment
  ✔ Compiling service
  ✖ Creating service
    → out of gas: out of gas in location: WritePerByte; gasWanted: 300000, gasUsed: 347768
    Starting service
    Fetching service's logs
Error: out of gas: out of gas in location: WritePerByte; gasWanted: 300000, gasUsed: 347768
    at API.<anonymous> (~/Development/MESG/js-sdk/packages/api/lib/lcd.js:58:23)
    at Generator.next (<anonymous>)
    at fulfilled (~/Development/MESG/js-sdk/packages/api/lib/lcd.js:5:58)

➜  js-sdk git:(bug/config-path) ./packages/cli/bin/run service:dev ../services/service-emit-event-interval
  ✔ Start environment
  ✔ Compiling service
  ✔ Creating service
  ✔ Starting service
  ✔ Fetching service's logs
(node:1) UnhandledPromiseRejectionWarning: Error: 2 UNKNOWN: create event: data invalid request: instance "En6ewB6q5Gh5s7V7E4ftTzkbFSV2ozeHgTB8QN7wMWAv" not found
    at Object.exports.createStatusError (/app/node_modules/grpc/src/common.js:91:15)
    at Object.onReceiveStatus (/app/node_modules/grpc/src/client_interceptors.js:1209:28)
    at InterceptingListener._callNext (/app/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/app/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/app/node_modules/grpc/src/client_interceptors.js:847:24)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1) [DEP0018] 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.
EVENT[every_2_seconds]: {"timestamp":1584706450623}
EVENT[every_1_second]: {"timestamp":1584706450638}
EVENT[every_1_second]: {"timestamp":1584706451643}
EVENT[every_2_seconds]: {"timestamp":1584706452623}
EVENT[every_1_second]: {"timestamp":1584706452646}
EVENT[every_5_seconds]: {"timestamp":1584706453623}
EVENT[every_1_second]: {"timestamp":1584706453648}
EVENT[every_2_seconds]: {"timestamp":1584706454591}
EVENT[every_1_second]: {"timestamp":1584706454615}
^C  ✔ Stopping logs
  ✔ Stop environment
 ›   Warning: Event stream error: 1 CANCELLED: Cancelled
 ›   Warning: Result stream error: 1 CANCELLED: Cancelled

➜  js-sdk git:(bug/config-path) docker service list
]ID                  NAME                                                  MODE                REPLICAS            IMAGE                                                                     PORTS
fmp8nhmaj1co        engine                                                replicated          1/1                 mesg/engine                                                               *:1317->1317/tcp, *:26656->26656/tcp, *:50052->50052/tcp
iitonbjnjx28        engine-8nMhm14WhFSZr2dGAgrH1xe86mUZLrQUNY2jnbBzoQ3G   replicated          1/1                 sha256:d84c5f68c5994d42bdc2aab41a88e8a457f86380b26fd051f90adc321ad115b4

Originally posted by @NicolasMahe in https://github.com/mesg-foundation/js-sdk/pull/197#issuecomment-601670084

NicolasMahe commented 4 years ago

Similar issue when ctrl+c during any step. The environment is not cleanup:

➜  js-sdk git:(master) ./packages/cli/bin/run process:dev ../process/process-webhook.yml --image mesg/engine:local
  ✔ Starting environment
  ⠧ Compiling process
    Creating process
    Fetching process's logs
^C

➜  js-sdk git:(master) docker ps -a
CONTAINER ID        IMAGE                 COMMAND             CREATED              STATUS              PORTS                                              NAMES
95499f1d029f        mesg/engine:local     "./engine"          About a minute ago   Up About a minute   0.0.0.0:1317->1317/tcp, 0.0.0.0:50052->50052/tcp   mesg_engine
antho1404 commented 4 years ago

Yes, the cleaning event is only at the end and should be moved to the first instruction of the command and cover more signals (only SIGINT for now). Some directions to solve that: https://stackoverflow.com/questions/14031763/doing-a-cleanup-action-just-before-node-js-exits

NicolasMahe commented 4 years ago

Any function during the stopping of logs, services, processes, and environment should have their errors catcher so the CLI can continue to cleanup the other stuff.

Got error because runner already stopped from other terminal:

➜  js-sdk git:(feature/dev-command-framework) ./packages/cli/bin/run dev ../app --version=local
  ✔ Starting environment
  ✔ Creating process "process-test.yml"
  ✔ Fetching logs
^C ›   Warning: Result stream error: 1 CANCELLED: Cancelled
  ✔ Stopping logs
  ✖ Stopping running services
    → invalid request: runner "DAqsSEWMEsEjD3txBbWVMVUKioYo1YzTmjjBYPC3MxSS" not found
    Deleting processes
    Stopping environment
(node:48941) UnhandledPromiseRejectionWarning: Error: invalid request: runner "DAqsSEWMEsEjD3txBbWVMVUKioYo1YzTmjjBYPC3MxSS" not found
    at Runner.<anonymous> (/Users/nico/Development/MESG/js-sdk/packages/api/lib/util/lcd.js:27:23)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/nico/Development/MESG/js-sdk/packages/api/lib/util/lcd.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:48941) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:48941) [DEP0018] 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.

Engine is still running:

➜  js-sdk git:(feature/dev-command-framework) docker ps -a
CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS              PORTS                                              NAMES
e97b61bfbac4        mesg/engine:local     "./engine"          4 minutes ago       Up 4 minutes        0.0.0.0:1317->1317/tcp, 0.0.0.0:50052->50052/tcp   mesg_engine
antho1404 commented 4 years ago

Issue migrated to liteflow-labs/liteflow-js#18