- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何解决这个错误,我用 AWS IoT 运行我的 Node.js 然后它有时会显示这个错误:
throw er; // Unhandled 'error' event
^
Error: How (/home/ec2-user/work/nodejs_27_01/node_modules/end-of-stream/index.js:54: 86)
at processTicksAndRejections (internal/process/task_queues.js:79:11)
Emitted 'error' event on DeviceClient instance at:
at MqttClient.<anonymous> (/home/ec2-user/work/nodejs_27_01/node_modules/aws-iot-device-sdk/ device/index.js:772:15)
at MqttClient.emit (events.js:333:22)
at MqttClient.EventEmitter.emit (domain.js:485:12)
at TLSSocket.f (/home/ec2-user/work/nodejs_27_01/node_modules/once/once.js:25:25)
at onclosenexttick (/home/ec2-user/work/nodejs_27_01/node_modules/end-of-stream/index.js:54: 73)
最佳答案
这可能有多种原因:
clientId 一次只能用于一个连接。如果您在建立另一个连接时使用相同的 clientId 进行连接,则旧连接将被丢弃(这会导致过早关闭错误)并建立新连接。
The client is using a client ID that is already in use. In this case, the client that is already connected will be disconnected [...]. (Source)
如果设备(来自 aws-iot-device-sdk-js 的 mqtt.Client)没有正确的权限来连接和/或发布/订阅/接收给定主题的消息,就会发生此错误。
有关更多文档,请参阅此处:https://docs.aws.amazon.com/iot/latest/developerguide/pub-sub-policy.html
策略应如下所示(示例显示 Cloudformation Iot Policy 资源):
MyIotThingsPolicy:
Type: AWS::IoT::Policy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action: iot:Connect
Effect: Allow
Resource: !Join [ "", [!Sub "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:client/",
"${iot:ClientId}"] ]
- Action: iot:Receive
Effect: Allow
Resource: !Join [ "", [!Sub "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:topic/",
"${iot:ClientId}/eg/your/broadcast/topic"] ]
- Action: iot:Subscribe
Effect: Allow
Resource: !Join [ "", [!Sub "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:topicfilter/",
"${iot:ClientId}/eg/your/broadcast/topic"] ]
- Action: iot:Publish
Effect: Allow
Resource: !Join [ "", [!Sub "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:topic/",
"${iot:ClientId}/eg/your/publish/topic"] ]
!Join
是必要的,因为 Cloudformation 会尝试解析 ${iot:ClientId}
,这是一个运行时值,在部署期间未知。
作为Sandeep Patel还建议,如果你想在客户端对这种情况采取行动,你应该实现错误回调:
device.on('error', (error) => {
// error.message might be 'premature close'
});
您还可以查找 disconnectReason
关于主题$aws/events/presence/disconnected/<clientId>
,参见:https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html
关于node.js - 如何解决 : premature close at onclosenexttick in Node. js 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59944783/
我一直在为我正在编写的应用程序而苦苦挣扎,我想我开始发现我的问题是过早的优化。我的完美主义一面希望在第一次通过时就使一切变得最佳和完美,但我发现这使设计变得相当复杂。我倾向于编写尽可能多的功能以提高效
We should develop on slow boxen because it forces us to optimize early. Randall Hyde 在 The Fallacy o
编辑:回答:我需要为“einlesen()”函数创建另一个游标。 这是我第一次在 Python 中使用 SQLite3,所以请原谅我(也许)可怕的语法;)我正在尝试构建一种 DVD 数据库,它直接从亚
result_t work(resource_t& resource) { lock_t ___(resource); return work_impl(resource); } 是否
我正在构建一项新服务,当我 curl 它时,我看到一条消息 Curl_http_done:称为过早。我找不到任何关于它的含义的文档,想知道我的服务是否不符合某些 http 规范? ➜ ~ git:(
我使用 Web-flux/Reactive 和 Webclient,在 tomcat 和 spring-boot 上运行它。 一切正常。我阅读了很多关于它的信息。问题好像是每当你使用webclient
我正在尝试使用 Stream 下载 xml 文件,一切都很好,直到 xml 大小变得大于 9 MB,所以我收到此错误java.io.IOException:过早的 EOF 这是代码 BufferedI
我正在尝试使用 urllib2 和 zlib 以及来自这两个 stackoverflow 问题的技术在 python 中处理从互联网上提取的大型 gzip 文件: > Python decompres
我一直在使用 JDOM 库通过 Java Servlet 读写 XML 文件。 问题是,当我使用 AJAX 向读取和写入 XML 文件中的数据的 servlet 发送许多请求时,很多时候它无法显示错误
我正在开发一个使用 C++ 编写的大型服务器应用程序。该服务器可能需要运行数月而不重新启动。碎片在这里已经是一个可疑的问题,因为我们的内存消耗会随着时间的推移而增加。到目前为止,测量是将私有(priv
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
我正在尝试通过套接字将图像文件从服务器发送到客户端。 套接字以前用于将一些字符串从服务器发送到客户端(使用缓冲的输入/输出流)。 问题是无法正确接收图像文件,出现“JPEG 文件过早结束”错误。 服务
出于某种原因,我收到了 HttpRequestException,其中包含消息“响应提前结束。我正在创建大约 500 个任务,这些任务使用我的 RateLimitedHttpClient 向网站发出请
我正在尝试使用阿尔卡特 OT900A 提交表单,但出现此错误 ava.io.IOException:损坏的表单数据:提前结束在 com.oreilly.servlet.multipart.Multip
当我尝试以这种方式解析来自网络的 XML 文件时: URL url = new URL("http://www.nbp.pl/kursy/xml/a074z120416.xml"); URLConne
我的代码有问题,但我不知道哪里出了问题。 我正在为客户编写应用程序。在启动画面期间,应用程序检查 Mysql 是否正在运行以便稍后能够连接到它。如果 mysql 处于打开状态,应用程序将继续启动。如果
import java.io.*; import com.lowagie.text.DocumentException; import org.xhtmlrenderer.pdf.ITextRende
我正在使用 OpenCV 从文件夹中读取图像。出现了很多这样的消息: Corrupt JPEG data: premature end of data segment Premature end of
这是有效的,但突然间我收到了这条错误消息。 “错误信息:脚本头过早结束:cust.php" "; echo "Back to main page"; } mysql_close(); ?> 请帮忙,提
项目开发中,链接mongodb的项目,偶尔报错com.mongodb.MongoSocketReadException: Prematurely reached end of stream 报错的详细
我是一名优秀的程序员,十分优秀!