gpt4 book ai didi

k6 - 调用 tcp : getsockopt: connection refused on local testing

转载 作者:行者123 更新时间:2023-12-04 13:30:32 50 4
gpt4 key购买 nike

我已经使用 k6 几天来在几个不同的环境中对 API 进行负载测试并追踪一些错误。

一切都很顺利,直到突然它开始在本地失败。

所有请求都会导致以下错误:

Request Failed error="Get http://localhost:8000: dial tcp [::1]:8000: getsockopt: connection refused"



这只发生在 k6 中;我仍然可以通过浏览器、Postman 和 cURL 成功调用本地 API。

有什么办法可以从 k6 中获取更多信息并找出它无法再连接的原因吗?

最佳答案

错误消息说 localhost正在解析 IPv6 地址( ::1 中的 [::1]:8000 ),因此如果您的 API 仅监听 IPv4 127.0.0.1但你的 localhost解析为 IPv4 和 IPv6 地址(k6 支持两者),那么这将解释错误。
如果您查看您的 /etc/hosts您可能有 localhost 的条目的文件看起来像这样:

127.0.0.1       localhost
::1 localhost
fe80::1%lo0 localhost
我不知道为什么要查找 localhost突然从 IPv4 更改为 IPv6,但可能是其中存在变量
您系统的地址选择算法(例如,请参阅 iOS/macOS 的 [1],以及更一般的 [2],Go 的内部解析器在不必通过系统的解析器时使用的)会导致基于诸如历史之类的东西进行切换TCP RTT(在 [1] 中作为一个因素提到)。
[1] https://www.ietf.org/mail-archive/web/v6ops/current/msg22455.html
[2] https://www.rfc-editor.org/rfc/rfc6724

关于k6 - 调用 tcp : getsockopt: connection refused on local testing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48895411/

50 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com