Files
kazoottt-blog/src/content/post/编程/前端/fetch 报错排查 SocketError other side closed.md
2024-11-23 15:50:51 +08:00

2.1 KiB
Raw Blame History

title, date, author, tags, published, slug, link, notionID, description, rinId, finished, category
title date author tags published slug link notionID description rinId finished category
fetch 报错排查 SocketError other side closed 2024-02-03T00:00:00.000Z KazooTTT
网络
true fetch-socketerror-other-side-closed https://kazoottt.notion.site/fetch-SocketError-other-side-closed-d399e7db398c4f7faaa8d3e0003327fd d399e7db-398c-4f7f-aaa8-d3e0003327fd 在main.js文件中使用fetch方法时遇到了报错错误信息显示“fetch failed”并指出“other side closed”。错误发生在getFansNum函数中具体是由于TLS连接的另一端关闭导致的。解决此问题的方法是关闭MitM中间人攻击工具这通常用于拦截和修改网络通信可能会导致不正常的连接关闭。 15 true 编程-前端

Fetch 报错

常规

排查 SocketError other side closed

在main.js中使用了fetch但是在运行main.js的时候时候fetch报错。

% node main.js

(node:51258) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/deps/undici/undici:11730
    Error.captureStackTrace(err, this);
          ^

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11730:11)
    at async getFansNum (/Users/kazoottt/GitHub/bilibili-fans/main.js:11:20) {
  cause: SocketError: other side closed
      at TLSSocket.onSocketEnd (node:internal/deps/undici/undici:8280:26)
      at TLSSocket.emit (node:events:526:35)
      at endReadableNT (node:internal/streams/readable:1589:12)
      at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
    code: 'UND_ERR_SOCKET',
    socket: {
      localAddress: '198.19.0.1',
      localPort: 55306,
      remoteAddress: '198.18.2.185',
      remotePort: 443,
      remoteFamily: 'IPv4',
      timeout: undefined,
      bytesWritten: 607,
      bytesRead: 0
    }
  }
}

Node.js v20.10.0

从报错信息中可以看出来是getFansNum这个方法中的fetch方法报了错。

解决方法:

关闭MitM