【应用服务 App Service】NodeJS +Egg 发布到App Service时遇见 [ERR_SYSTEM_ERROR]: A system error occurred:uv_os_get_passwd returned ENOENT(no such file or directory)

简介: 【应用服务 App Service】NodeJS +Egg 发布到App Service时遇见 [ERR_SYSTEM_ERROR]: A system error occurred:uv_os_get_passwd returned ENOENT(no such file or directory)

问题情形

本地NodeJS应用使用Egg脚手架构建,本地运行测试完全没有问题,发布后App Service后不能运行。通过登录到kudu后(https://<your web site>.scm.chinacloudsites.cn)后,在日志中发现找不到一个文件或路径的错误。通过在kudu的CMD窗口执行npm start命令,发现错误是一致,怀疑是对Egg中某个框架的不支持。

详细日志

Application has thrown an uncaught exception and is terminated:

SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)

    at Object.userInfo (os.js:272:11)

    at module.exports (D:\home\site\wwwroot\pynode\node_modules\node-homedir\index.js:10:26)

    at AppWorkerLoader.getHomedir (D:\home\site\wwwroot\pynode\node_modules\egg-core\lib\loader\egg_loader.js:163:36)

    at AppWorkerLoader.getAppInfo (D:\home\site\wwwroot\pynode\node_modules\egg-core\lib\loader\egg_loader.js:174:23)

    at new EggLoader (D:\home\site\wwwroot\pynode\node_modules\egg-core\lib\loader\egg_loader.js:87:25)

    at new AppWorkerLoader (D:\home\site\wwwroot\pynode\node_modules\egg\lib\loader\app_worker_loader.js:9:1)

    at new EggCore (D:\home\site\wwwroot\pynode\node_modules\egg-core\lib\egg.js:118:19)

    at new EggApplication (D:\home\site\wwwroot\pynode\node_modules\egg\lib\egg.js:43:5)

    at new Application (D:\home\site\wwwroot\pynode\node_modules\egg\lib\application.js:60:5)

    at Object.<anonymous> (D:\home\site\wwwroot\pynode\index.js:3:13)

在详细的log文件中,可以看见全面的错误信息。并指出了报错的源文件为:(D:\home\site\wwwroot\pynode\node_modules\node-homedir\index.js:10:26),在源代码中,找出了问题的根源。

问题原因

node_modules\node-homedir\index.js 源码:

1 'use strict';

2

3 const os = require('os');

4

5 module.exports = () => {

6   if (process.env.MOCK_HOME_DIR) return process.env.MOCK_HOME_DIR;

7

8   if (typeof os.userInfo === 'function') {

9     try {

10       const homedir =os.userInfo().homedir;

11       if (homedir) return homedir;

12     } catch (err) {

13       if (err.code !== 'ENOENT') throw err;

14    }

15  }

16

17   if (typeof os.homedir === 'function') {

18     return os.homedir();

19  }

20

21   return process.env.HOME;

22 };

在第十行代码中,使用了os对象,而在App Service中,由于是sandbox 模式下,所以某些操作被禁止了。关于禁止的说明可以参考:https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#general-sandbox-restrictions

解决方案

在查看源代码后,想解决它就有两种办法:

1) 在修改node-homedir\index.js中的源代码,把里面 os.userInfo().homedir 的部分替换成在App Service中的Homedir路径,hardcode这一部分。如  const homedir =”D:\home\site\wwwroot\“;//os.userInfo().homedir;

2) 最快速且无代码改动方案。在App Service的应用程序设置中(Applicaiton Settings)添加一个名MOCK_HOME_DIR的设置,并设置其值为D:\home\site\wwwroot\ (为应用程序发布的默认路径)。 这样node-homedir的源代码就不会进入到os部分。直接在第一行就返回需要的homedir.

 

PS: 这里是把NodeJS的应用发布在Windows的环境中遇见的问题,如发布在App Service For Linux则可以避免类似问题。

相关文章
|
安全 Java 应用服务中间件
【Azure 应用服务】App Service 默认页面暴露Tomcat版本信息,存在安全风险
【Azure 应用服务】App Service 默认页面暴露Tomcat版本信息,存在安全风险
305 2
|
12月前
|
固态存储 Shell 调度
初步认识操作系统(Operator System)
管理者管理被管理者,实际上是先将被管理者的各种信息进行描述,然后再将多个被管理者的描述信息根据某种数据结构组织起来,最后管理者管理被管理者实际上就是对数据结构的管理。
444 0
|
存储 网络安全
Curl error (60): SSL peer certificate or SSH remote key was not OK for https://update.cs2c.com.cn/NS/V10/V10SP2/os/adv/lic/base/x86_64/repodata/repomd.xml [SSL: no alternative certificate subject name matches target host name 'update.cs2c.com.cn']
【10月更文挑战第30天】在尝试从麒麟软件仓库(ks10-adv-os)下载元数据时,遇到 SSL 证书验证问题。错误提示为:`Curl error (60): SSL peer certificate or SSH remote key was not OK`。可能原因包括证书不被信任、证书与域名不匹配或网络问题。解决方法包括检查网络连接、导入 SSL 证书、禁用 SSL 证书验证(不推荐)、联系仓库管理员、检查系统时间和尝试其他镜像。
4919 1
【Azure Logic App】使用Event Hub 连接器配置 Active Directory OAuth 认证无法成功连接到中国区Event Hub的解决之法
An exception occurred while retrieving properties for Event Hub: logicapp. Error Message: 'ClientSecretCredential authentication failed: AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Che
243 3
|
应用服务中间件 Linux 网络安全
【Azure 应用服务】App Service for Linux 环境中为Tomcat页面修改默认的Azure 404页面
【Azure 应用服务】App Service for Linux 环境中为Tomcat页面修改默认的Azure 404页面
284 5
【Azure Logic App】使用Event Hub 连接器配置 Active Directory OAuth 认证无法成功连接到中国区Event Hub
【Azure Logic App】使用Event Hub 连接器配置 Active Directory OAuth 认证无法成功连接到中国区Event Hub
207 2
|
JavaScript Linux
【Azure App Service for Linux】NodeJS镜像应用启动失败,遇见 RangeError: Incorrect locale information provided
【Azure App Service for Linux】NodeJS镜像应用启动失败,遇见 RangeError: Incorrect locale information provided
391 0
|
JavaScript
【Azure Function App】Nodejs Function遇见WorkerProcessExitException : node exited with code -1073740791 (0xC0000409) 错误
【Azure Function App】Nodejs Function遇见WorkerProcessExitException : node exited with code -1073740791 (0xC0000409) 错误
212 0
|
Shell PHP Windows
【Azure App Service】Web Job 报错 UNC paths are not supported. Defaulting to Windows directory.
【Azure App Service】Web Job 报错 UNC paths are not supported. Defaulting to Windows directory.
299 0
|
Docker 容器
【Azure 应用服务】App Service for Container 无法拉取Docker Hub中的镜像替代方案
【Azure 应用服务】App Service for Container 无法拉取Docker Hub中的镜像替代方案
290 0

热门文章

最新文章

推荐镜像

更多