添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account Client network socket disconnected before secure TLS connection was established error while creating a secure websocket connection #1529 Client network socket disconnected before secure TLS connection was established error while creating a secure websocket connection #1529 shaiksyedali opened this issue Mar 13, 2019 · 3 comments var WebSocketServer = WebSocket.Server; var wss = new WebSocketServer({ verifyClient: (info) => { console.log('Request from client :'+ info.req.rawHeaders); console.log('Request from client auth :'+ info.req.client.authorized); success = !!info.req.client.authorized; return success; server: httpsServer

Client Code:

const ws = new WebSocket('wss://localhost:8989/',
          'com.hp.cdm.service.ioFilter.version.1.type.filterStream', {
            cert: fs.readFileSync(path.normalize(serverCertPath)),
            key: fs.readFileSync(path.normalize(serverKeyPath)),
            ca: fs.readFileSync(path.normalize(caCert)),
            passphrase: 'test',
            rejectUnauthorized: false,

When I try to make a connection from client to server, I am getting the following error,

{ Error: Client network socket disconnected before secure TLS connection was established
at TLSSocket.onConnectEnd (_tls_wrap.js:1086:19)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
code: 'ECONNRESET',
path: undefined,
host: 'localhost',
port: '8989',
localAddress: undefined }

What am I doing error? Any TLS version mismatch? Or some certificate error?

Reproducible in:

  • version:
  • Node.js version(s):
  • OS version(s):
  • Steps to reproduce:

    On your server add a 'request' handler

    httpsServer.on('request', function(req, res) {
      res.end('OK');
    });

    Then use https://nodejs.org/api/https.html#https_https_get_url_options_callback to debug. When it works use the same options on ws.

    method: 'GET', key: fs.readFileSync(path.normalize(serverKeyPath)), cert: fs.readFileSync(path.normalize(serverCertPath)), ca: fs.readFileSync(path.normalize(caCertPath)), passphrase: 'test', const https = require('https'); const req = https.request(options, (res: any) => { res.on('data', (data: any) => { // tslint:disable-next-line:no-console console.log(data); req.end(); req.on('error', (e: any) => { // tslint:disable-next-line:no-console console.error(e);

    Server:

    var options = { 
    	key: clientKey, 
    	cert: clientCert, 
    	ca: caCert,
    	passphrase: 'test',
    	requestCert: true
    var httpsServer = https.createServer(options, function (req, res) { 
    	console.log('Received request');
        res.writeHead(200); 
        res.end("hello world\n"); 
    

    Now when I make a GET request from the client to the server, I am getting the same error. The request is not going to the server.

    Error: Client network socket disconnected before secure TLS connection was established
        at TLSSocket.onConnectEnd (_tls_wrap.js:1086:19)
        at Object.onceWrapper (events.js:273:13)
        at TLSSocket.emit (events.js:187:15)
        at endReadableNT (_stream_readable.js:1094:12)
        at process._tickCallback (internal/process/next_tick.js:63:19)
      code: 'ECONNRESET',
      path: null,
      host: 'localhost',
      port: 8989,
      localAddress: undefined }