ulixee/platform

miner crashes when calling `hero.close()` while still active in another async function

GlenDC opened this issue · 1 comments

For my usage of @ulixee/hero, I put a max timeout on my hero script, as to ensure it can never use my resources for too long. Problem is however that this means that there's a Promise.race with my timeout going first, and thus my hero runner still being active. This gives issues now as I do call hero.close() to make sure to close it all up, but now miner is trying to send messages over a closed connection, while it is already closed.

What do I expetct?

That it does not crash. Feel free to log it, but there should be no reason to crash over a faulty hero client that disconnects.

Example output:

2022-11-23T21:18:30.134Z ERROR [hero-core/index] UnhandledErrorOrRejection { context: {}, sessionId: null, sessionName: undefined } DisconnectedError: This transport has been disconnected (host: ws://localhost:65262)
    at ConnectionToHeroCore.onResponse (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:209:25)
    at ConnectionToHeroCore.onMessage (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:190:12)
    at WsTransportToCore.emit (node:events:513:28)
    at WsTransportToCore.emit (node:domain:489:12)
    at WsTransportToCore.emit (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/TypedEventEmitter.ts:136:18)
    at WsTransportToCore.onMessage (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/WsTransportToCore.ts:112:10)
    at WebSocket.emit (node:events:513:28)
    at WebSocket.emit (node:domain:489:12)
    at Receiver.receiverOnMessage (/Users/my-project/.yarn/__virtual__/ws-virtual-460e344056/0/cache/ws-npm-7.5.9-26f12a5ed6-c3c100a181.zip/node_modules/ws/lib/websocket.js:1068:20)
    at Receiver.emit (node:events:513:28)
------CONNECTION----------------------------------
    at new Resolvable (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Resolvable.ts:16:18)
    at createPromise (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/utils.ts:168:10)
    at PendingMessages.create (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/PendingMessages.ts:47:44)
    at ConnectionToHeroCore.sendRequest (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:153:50)
    at async CoreCommandQueue.sendRequest (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:287:12)
    at async Object.cb (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:229:16)
    at async Queue.next (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Queue.ts:95:19)
------CORE COMMANDS-------------------------------
    at Queue.run (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Queue.ts:40:19)
    at CoreCommandQueue.run (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:218:8)
    at CoreTab.waitForMillis (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreTab.ts:292:29)
    at Tab.waitForMillis (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/Tab.ts:344:19)

--------------------------------------------------
------brorun-core-4-------------------------------
------BC48U3pWFhe-WHqU2vahq-----------------------
-------------------------------------------------- {
  host: 'ws://localhost:65262',
  code: 'DisconnectedError'
}
DisconnectedError: This transport has been disconnected (host: ws://localhost:65262)
    at ConnectionToHeroCore.onResponse (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:209:25)
    at ConnectionToHeroCore.onMessage (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:190:12)
    at WsTransportToCore.emit (node:events:513:28)
    at WsTransportToCore.emit (node:domain:489:12)
    at WsTransportToCore.emit (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/TypedEventEmitter.ts:136:18)
    at WsTransportToCore.onMessage (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/WsTransportToCore.ts:112:10)
    at WebSocket.emit (node:events:513:28)
    at WebSocket.emit (node:domain:489:12)
    at Receiver.receiverOnMessage (/Users/my-project/.yarn/__virtual__/ws-virtual-460e344056/0/cache/ws-npm-7.5.9-26f12a5ed6-c3c100a181.zip/node_modules/ws/lib/websocket.js:1068:20)
    at Receiver.emit (node:events:513:28)
------CONNECTION----------------------------------
    at new Resolvable (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Resolvable.ts:16:18)
    at createPromise (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/utils.ts:168:10)
    at PendingMessages.create (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/PendingMessages.ts:47:44)
    at ConnectionToHeroCore.sendRequest (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:153:50)
    at async CoreCommandQueue.sendRequest (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:287:12)
    at async Object.cb (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:229:16)
    at async Queue.next (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Queue.ts:95:19)
------CORE COMMANDS-------------------------------
    at Queue.run (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Queue.ts:40:19)
    at CoreCommandQueue.run (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:218:8)
    at CoreTab.waitForMillis (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreTab.ts:292:29)
    at Tab.waitForMillis (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/Tab.ts:344:19)

--------------------------------------------------
------brorun-core-4-------------------------------
------BC48U3pWFhe-WHqU2vahq-----------------------
-------------------------------------------------- {
  host: 'ws://localhost:65262',
  code: 'DisconnectedError'
}
DisconnectedError: This transport has been disconnected (host: ws://localhost:65262)
    at ConnectionToHeroCore.onResponse (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:209:25)
    at ConnectionToHeroCore.onMessage (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:190:12)
    at WsTransportToCore.emit (node:events:513:28)
    at WsTransportToCore.emit (node:domain:489:12)
    at WsTransportToCore.emit (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/TypedEventEmitter.ts:136:18)
    at WsTransportToCore.onMessage (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/WsTransportToCore.ts:112:10)
    at WebSocket.emit (node:events:513:28)
    at WebSocket.emit (node:domain:489:12)
    at Receiver.receiverOnMessage (/Users/my-project/.yarn/__virtual__/ws-virtual-460e344056/0/cache/ws-npm-7.5.9-26f12a5ed6-c3c100a181.zip/node_modules/ws/lib/websocket.js:1068:20)
    at Receiver.emit (node:events:513:28)
------CONNECTION----------------------------------
    at new Resolvable (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Resolvable.ts:16:18)
    at createPromise (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/utils.ts:168:10)
    at PendingMessages.create (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/PendingMessages.ts:47:44)
    at ConnectionToHeroCore.sendRequest (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:153:50)
    at async CoreCommandQueue.sendRequest (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:287:12)
    at async Object.cb (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:229:16)
    at async Queue.next (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Queue.ts:95:19)
------CORE COMMANDS-------------------------------
    at Queue.run (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Queue.ts:40:19)
    at CoreCommandQueue.run (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:218:8)
    at CoreTab.waitForMillis (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreTab.ts:292:29)
    at Tab.waitForMillis (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/Tab.ts:344:19)

--------------------------------------------------
------brorun-core-4-------------------------------
------BC48U3pWFhe-WHqU2vahq-----------------------
-------------------------------------------------- {
  host: 'ws://localhost:65262',
  code: 'DisconnectedError'
}
2022-11-23T21:18:30.141Z ERROR [hero-core/index] UnhandledError(fatal) {
  clientError: 'abort({"message":"This transport has been disconnected (host: ws://localhost:65262)","name":"DisconnectedError","host":"ws://localhost:65262","code":"DisconnectedError","stack":"DisconnectedError: This transport has been disconnected (host: ws://localhost:65262)\\n    at ConnectionToHeroCore.onResponse (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:209:25)\\n    at ConnectionToHeroCore.onMessage (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:190:12)\\n    at WsTransportToCore.emit (node:events:513:28)\\n    at WsTransportToCore.emit (node:domain:489:12)\\n    at WsTransportToCore.emit (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/TypedEventEmitter.ts:136:18)\\n    at WsTransportToCore.onMessage (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/WsTransportToCore.ts:112:10)\\n    at WebSocket.emit (node:events:513:28)\\n    at WebSocket.emit (node:domain:489:12)\\n    at Receiver.receiverOnMessage (/Users/my-project/.yarn/__virtual__/ws-virtual-460e344056/0/cache/ws-npm-7.5.9-26f12a5ed6-c3c100a181.zip/node_modules/ws/lib/websocket.js:1068:20)\\n    at Receiver.emit (node:events:513:28)\\n------CONNECTION----------------------------------\\n    at new Resolvable (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Resolvable.ts:16:18)\\n    at createPromise (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/utils.ts:168:10)\\n    at PendingMessages.create (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/PendingMessages.ts:47:44)\\n    at ConnectionToHeroCore.sendRequest (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:153:50)\\n    at async CoreCommandQueue.sendRequest (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:287:12)\\n    at async Object.cb (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:229:16)\\n    at async Queue.next (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Queue.ts:95:19)\\n------CORE COMMANDS-------------------------------\\n    at Queue.run (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Queue.ts:40:19)\\n    at CoreCommandQueue.run (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:218:8)\\n    at CoreTab.waitForMillis (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreTab.ts:292:29)\\n    at Tab.waitForMillis (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/Tab.ts:344:19)\\n\\n--------------------------------------------------\\n------brorun-core-4-------------------------------\\n------BC48U3pWFhe-WHqU2vahq-----------------------\\n--------------------------------------------------"}). Build with -s ASSERTIONS=1 for more info.',
  context: {},
  sessionId: null,
  sessionName: undefined
}

/Users/my-project/.yarn/cache/opencv-wasm-npm-4.3.0-alpha.2-f46878c772-87c1e21ca9.zip/node_modules/opencv-wasm/opencv.js:91
                          throw ex
                          ^
abort({"message":"This transport has been disconnected (host: ws://localhost:65262)","name":"DisconnectedError","host":"ws://localhost:65262","code":"DisconnectedError","stack":"DisconnectedError: This transport has been disconnected (host: ws://localhost:65262)\n    at ConnectionToHeroCore.onResponse (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:209:25)\n    at ConnectionToHeroCore.onMessage (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:190:12)\n    at WsTransportToCore.emit (node:events:513:28)\n    at WsTransportToCore.emit (node:domain:489:12)\n    at WsTransportToCore.emit (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/TypedEventEmitter.ts:136:18)\n    at WsTransportToCore.onMessage (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/WsTransportToCore.ts:112:10)\n    at WebSocket.emit (node:events:513:28)\n    at WebSocket.emit (node:domain:489:12)\n    at Receiver.receiverOnMessage (/Users/my-project/.yarn/__virtual__/ws-virtual-460e344056/0/cache/ws-npm-7.5.9-26f12a5ed6-c3c100a181.zip/node_modules/ws/lib/websocket.js:1068:20)\n    at Receiver.emit (node:events:513:28)\n------CONNECTION----------------------------------\n    at new Resolvable (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Resolvable.ts:16:18)\n    at createPromise (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/utils.ts:168:10)\n    at PendingMessages.create (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/PendingMessages.ts:47:44)\n    at ConnectionToHeroCore.sendRequest (/Users/my-project/.yarn/cache/@ulixee-net-npm-2.0.0-alpha.15-661d373677-270ac0b68f.zip/node_modules/net/lib/ConnectionToCore.ts:153:50)\n    at async CoreCommandQueue.sendRequest (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:287:12)\n    at async Object.cb (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:229:16)\n    at async Queue.next (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Queue.ts:95:19)\n------CORE COMMANDS-------------------------------\n    at Queue.run (/Users/my-project/.yarn/cache/@ulixee-commons-npm-2.0.0-alpha.15-ee6940f946-9f14da600f.zip/node_modules/commons/lib/Queue.ts:40:19)\n    at CoreCommandQueue.run (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreCommandQueue.ts:218:8)\n    at CoreTab.waitForMillis (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/CoreTab.ts:292:29)\n    at Tab.waitForMillis (/Users/my-project/.yarn/cache/@ulixee-hero-npm-2.0.0-alpha.15-d23b675b96-096f8f05e0.zip/node_modules/client/lib/Tab.ts:344:19)\n\n--------------------------------------------------\n------brorun-core-4-------------------------------\n------BC48U3pWFhe-WHqU2vahq-----------------------\n--------------------------------------------------"}). Build with -s ASSERTIONS=1 for more info.
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js v18.12.1

Per Discord, no longer seeing this. Could be due to switching to full stack, but closing for now unless someone is actively experiencing it.