简体   繁体   English

在 aws 节点 10 lambda 中执行子进程后,节点生成子进程不执行命令

[英]Node spawn child process doesn't execute the command after exec child process in aws node 10 lambda

I am attempting to run 2 child processes, but one seems to be blocked and eventually times out the node lambda.我正在尝试运行 2 个子进程,但其中一个似乎被阻止并最终使节点 lambda 超时。

Environment:环境:

  • AWS node 10 lambda running in a docker container. AWS 节点 10 lambda 在 docker 容器中运行。
  • Accesses ffmpeg and ffprobe via a lambda layer in the /opt/bin directory.通过 /opt/bin 目录中的 lambda 层访问 ffmpeg 和 ffprobe。

child_process.exec I am running ffprobe in a child_process.exec to get the file format of an audio file. child_process.exec我在 child_process.exec 中运行 ffprobe 以获取音频文件的文件格式。 I am using exec because the output is a small json response (which shouldn't consume much memory).我使用 exec 因为 output 是一个小的 json 响应(它不应该消耗太多内存)。

child_process.spawn Shortly after I run ffmpeg to convert the audio file to mp3 using child_process.spawn. child_process.spawn在我运行 ffmpeg 以使用 child_process.spawn 将音频文件转换为 mp3 后不久。

The problem is the FFMPEG child_process.spawn command doesn't run after ffprobe (even though ffprobe successfully completes).问题是 FFMPEG child_process.spawn 命令在 ffprobe 之后没有运行(即使 ffprobe 成功完成)。 If I don't run the ffprobe command the FFMPEG command runs perfectly.如果我不运行 ffprobe 命令 FFMPEG 命令运行完美。

Which leads me to believing this is an issue with how I am dealing with child processes in node.这让我相信这是我如何处理节点中的子进程的问题。

Is it possible the child_process.exec ffprobe command is somehow still running/ blocking the new ffmpeg (child_process.spawn) command from running - if so how do I check this? child_process.exec ffprobe 命令是否可能仍在运行/阻止新的 ffmpeg (child_process.spawn) 命令运行 - 如果是这样,我该如何检查?

When I access the running processes in the docker container only the new ffmpeg command seems to be running, although it consumes no memory and just hangs - seemingly doing nothing.当我访问 docker 容器中正在运行的进程时,只有新的 ffmpeg 命令似乎正在运行,尽管它不消耗 memory 并且只是挂起 - 似乎什么都不做。 I even tried launching the ffmpeg command from the docker cli (avoiding using the node env) and this works fine and runs as expected.我什至尝试从 docker cli 启动 ffmpeg 命令(避免使用节点环境),这工作正常并按预期运行。

So it seems my issue wasn't really between exec and spawn, I am not 100% sure but I think it could be that the child process was preserved in the container and resumed in the next invocation of the lambda.所以看起来我的问题并不是真的在 exec 和 spawn 之间,我不是 100% 确定,但我认为可能是子进程被保存在容器中,并在下一次调用 lambda 时恢复。

Changing to child_process.spawnSync waits until the child process exits and keeps things cleaner and I haven't encountered this problem since using this.更改为 child_process.spawnSync 等到子进程退出并保持清洁,自从使用它以来我还没有遇到过这个问题。

A more thorough explanation from someone else would be really appreciated.非常感谢其他人的更彻底的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM