cazala / coin-hive

CoinHive cryptocurrency miner for node.js
https://www.npmjs.com/package/coin-hive
MIT License
1.99k stars 399 forks source link

Not able to start in Azure AppService NodeJS WebApp environment #98

Open joymon opened 6 years ago

joymon commented 6 years ago

Please read this before submitting:

This project has nothing to do with coinhive.com

What this package does is just the following:

  1. Launch a local server that serves a page where CoinHive's Javascript miner is embedded.

  2. Launch puppeteer (a headless chrome) pointing to that page.

  3. Expose an API that allows you to interact with that miner from node.js (starting, stopping, etc).

The purpose of this package is to allow you to run CoinHive's JavaScript miner from node.js (otherwise it only works on the browser).

If you have an issue with CoinHive's JavaScript miner, or with coinhive.com website, you should read their FAQs and contact them here:

https://coinhive.com/contact

Thanks for reading ^.^ if you do have an issue with this package (have a question, found a bug, feature request) then please do submit it

<3 I tried to run this from Microsoft Azure WebApp (a cloud Platform as a Service offering). But it failed. The error details below. Error: spawn UNKNOWN at _errnoException (util.js:1022:11) at ChildProcess.spawn (internal/child_process.js:323:11) at Object.exports.spawn (child_process.js:502:9) at Function.launch (D:\home\site\wwwroot\node_modules\puppeteer\lib\Launcher.js:81:40) at Function.launch (D:\home\site\wwwroot\node_modules\puppeteer\lib\Puppeteer.js:25:21) at Puppeteer.getBrowser (D:\home\site\wwwroot\node_modules\coin-hive\src\puppeteer.js:44:36) at Puppeteer.getPage (D:\home\site\wwwroot\node_modules\coin-hive\src\puppeteer.js:52:32) at Puppeteer.init (D:\home\site\wwwroot\node_modules\coin-hive\src\puppeteer.js:66:29) at getRunner (D:\home\site\wwwroot\node_modules\coin-hive\src\index.js:48:15) at code: 'UNKNOWN', errno: 'UNKNOWN', syscall: 'spawn' } started (node:14044) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): ReferenceError: miner is not defined (node:14044) [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. Application has thrown an uncaught exception and is terminated:

It seems the Puppeteer the headless browser is not supported in sandboxed Azure environment and coin-hive depends on that. Link below.

https://github.com/GoogleChrome/puppeteer/issues/515

Is there any workaround/hack to get mining work in Azure AppService?

leidegre commented 6 years ago

My last comment really says it all. Although I don't know anything about coin-hive it's impossible to run chrome headless within the Azure runtime as it stands today. You have to fix the API usage in a custom chrome build. However, the Azure runtime is restricted to not allow all debugging tools which makes root causing difficult.

If you knew what was wrong you could theoretically patch chrome but the problem is that you can't really tell which APIs are causing issues because sxtrace won't start.

However, you can use the Azure Service Fabric and run a Linux container with chrome headless. I would recommend this.

Microsoft is currently working on a fully managed solution for this. In the future you won't have to manage virtual machines yourself.

leidegre commented 6 years ago

I should add that you can use a windows container as well, if you really need a windows environment.