簡體   English   中英

錯誤:關閉瀏覽器/選項卡時在 TLSWrap.onStreamRead 讀取 ECONNRESET

[英]Error: read ECONNRESET at TLSWrap.onStreamRead when closing the browser/tabs

我在 nodejs 中編寫我的第一個聊天應用程序,我的應用程序基本上跟蹤在線用戶並將他們放在房間里通過 webrtc 聊天...我使用 pm2 運行聊天服務器

所以我注意到有時當我關閉瀏覽器選項卡時我的應用程序會崩潰並且 pm2 會重新加載服務器所以我檢查了日志並看到了這個錯誤

0|chat  | Error: read ECONNRESET
0|chat  |     at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20) {
0|chat  |   errno: -104,
0|chat  |   code: 'ECONNRESET',
0|chat  |   syscall: 'read'
0|chat  | }

這是在沒有 pm2 的情況下運行時的錯誤

node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20)
Emitted 'error' event on TLSSocket instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read'
}

為了確保不是我的代碼導致了這個錯誤,我刪除了我的應用程序中的所有代碼,只放了 2 個簡單的 function 來在線收聽(由在線客戶端通過 socket.io 調用)和斷開連接(由用戶斷開連接自動調用)事件。 . 確實在關閉和打開一些選項卡后再次發生這里是我的代碼的簡化版本

我正在使用Express.io ,它是 Express 和 Socket.io 的組合

const  env = require('dotenv').config({ path: '.env' })
const https = require('https');
const fs = require('fs');

app = require('express.io')();

var options = {
    key: fs.readFileSync( env.parsed.SSL_KEY),
    cert: fs.readFileSync(env.parsed.SSL_CERT)
};
app.https(options).io();
console.log('|-> protocol : https ');



app.io.route('online' , function (req){
    console.log(`| online socket -> ${req.socket.id}`);
})


app.io.route('disconnect', function(req) {
    console.log(`|->****************** disconnect : ${req.socket.id}`);
});

var PORT = env.parsed.PORT  || 8080
console.log(`|-> listining to port ${PORT} `);
app.listen(PORT );

我已經在線搜索並知道它為什么會發生(我認為)但我沒有在此代碼中進行任何數據通信......我不知道如何處理這個並感謝任何幫助

這是完整的日志,您可以在關閉某些選項卡后看到它發生

在此處輸入圖像描述

/root/.pm2/logs/chat-out.log last 15 lines:
0|chat     | |-> protocol : https
0|chat     | |-> listining to port 8080

/root/.pm2/logs/chat-error.log last 15 lines:
0|chat     | (node:19821) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
0|chat     | (Use `node --trace-deprecation ...` to show where the warning was created)

0|chat  | | online socket -> Z2z7m6D9OXKPGRVhbz4R
0|chat  | |->****************** disconnect : H_1-d7sIm2oIvxzzbz4Q
0|chat  | | online socket -> JrnLWbqN4luBtYg4bz4S
0|chat  | | online socket -> ZSY1wIywMEdmUcALbz4T
0|chat  | | online socket -> ugSg08DksJ73ld1Rbz4U
0|chat  | |->****************** disconnect : ugSg08DksJ73ld1Rbz4U
0|chat  | |->****************** disconnect : ZSY1wIywMEdmUcALbz4T
0|chat  | Error: read ECONNRESET
0|chat  |     at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20) {
0|chat  |   errno: -104,
0|chat  |   code: 'ECONNRESET',
0|chat  |   syscall: 'read'
0|chat  | }
PM2     | App [chat:0] exited with code [1] via signal [SIGINT]
PM2     | App [chat:0] starting in -fork mode-
PM2     | App [chat:0] online
0|chat  | |-> protocol : https
0|chat  | |-> listining to port 8080
0|chat  | (node:19864) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
0|chat  | (Use `node --trace-deprecation ...` to show where the warning was created)

沒有看到客戶端代碼就很難找出問題,但我敢打賭是通過聲明這條路線

app.io.route('disconnect', function(req) {
    console.log(`|->****************** disconnect : ${req.socket.id}`);
});

你濫用了express.io庫:

https://github.com/techpines/express.io/tree/master/lib#reserved-events

這些事件是保留的,不應與app.io.routereq.io.on一起使用,除非您知道自己在做什么。

  • 連接
  • 連接
  • 斷開
  • 連接失敗
  • 錯誤
  • 信息
  • 重新連接失敗
  • 重新連接
  • 重新連接

順便說一句,就像另一條評論所說的那樣,這個庫很舊,你不應該使用它。 它使用 Socket.IO v0.9,當前版本是 v4。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM