GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tls throws when working with JSStreams · Issue #12716 · nodejs/node

tls throws when working with JSStreams #12716

New issue
Copy link
New issue
Copy link
Closed
Closed
tls throws when working with JSStreams#12716
Copy link
Labels
tlsIssues and PRs related to the tls subsystem.

Description

@coolaj86
coolaj86
opened on Apr 28, 2017
Issue body actions

Version: v7.7.4
Platform: Darwin
Subsystem: tls

Here's the lovely error:

Assertion failed: (uv__stream_fd(stream) >= 0), function uv_read_start, file ../deps/uv/src/unix/stream.c, line 1545.

And here's how you can too:

'use strict';

var net = require('net');
var tls = require('tls');
// just a simple wrapper around a duplex to create both halves of a socket - very very simple
// https://github.com/indutny/stream-pair/blob/master/lib/stream-pair.js
var streamPair = require('stream-pair');

var netServer = net.createServer(handleTcp);

// just some certs so that it's easy to test all this
var tlsOptions = require('localhost.daplie.me-certificates').merge({});
var tlsServer = tls.createServer(tlsOptions, handleTls);

function handleTcp(conn) {
  tlsServer.emit('connection', conn);
}

function handleTls(conn) {
  conn.on('data', function (chunk) {
    console.log(chunk.toString('utf8'));
  });
}

var writer = streamPair.create();
var reader = writer.other;

netServer.emit('connection', reader);

// generated in this way
// nc -l 3000 > /tmp/sni.bin
// https://localhost.daplie.me:3000/
// hexdump -ve '1/1 "%.2x"' /tmp/sni.bin
var sni = '16030100ce010000ca03032d4ad3b5daf224a8465309487ed334c91de34c05ca5bf1c042ef54c510aadea80000202a2ac02bc02fc02cc030cca9cca8cc14cc13c013c014009c009d002f0035000a01000081dada0000ff010001000000001800160000136c6f63616c686f73742e6461706c69652e6d650017000000230000000d00140012040308040401050308050501080606010201000500050100000000001200000010000e000c02683208687474702f312e3175500000000b00020100000a000a00084a4a001d00170018baba000100';
writer.write(Buffer.from(sni, 'hex'));

and since all of my issues go to you anyway, might as well:

cc/ @indutny

May be related to:

  • tls: accept empty net.Sockets #1046
  • Assertion failed: (uv__stream_fd(stream) >= 0), function uv_read_start, file ../deps/uv/src/unix/stream.c, line 1477. #987

Activity

  1. mscdex
    added
    tlsIssues and PRs related to the tls subsystem.
    on Apr 28, 2017
  2. coolaj86 commented on Apr 28, 2017

    @coolaj86
    coolaj86
    on Apr 28, 2017
    Author
    More actions

    Workaround

    Create a unix socket or windows pipe just for the sake of getting that fd so that the tls module can do its binary magic:

    https://git.daplie.com/Daplie/socket-pair

    'use strict';
    
    var net = require('net');
    var tls = require('tls');
    // just a simple wrapper around a server and socket to create both of the necessary halves
    // https://git.daplie.com/Daplie/socket-pair/blob/master/lib/socket-pair.js
    
    var netServer = net.createServer(handleTcp);
    
    // just some certs so that it's easy to test all this
    var tlsOptions = require('localhost.daplie.me-certificates').merge({});
    var tlsServer = tls.createServer(tlsOptions, handleTls);
    
    function handleTcp(conn) {
      tlsServer.emit('connection', conn);
    }
    
    function handleTls(conn) {
      conn.on('data', function (chunk) {
        console.log(chunk.toString('utf8'));
      });
    }
    
    var writer = require('socket-pair').create(function (err, reader) {
      netServer.emit('connection', reader);
    
      // generated in this way
      // nc -l 3000 > /tmp/sni.bin
      // https://localhost.daplie.me:3000/
      // hexdump -ve '1/1 "%.2x"' /tmp/sni.bin
      var sni = '16030100ce010000ca03032d4ad3b5daf224a8465309487ed334c91de34c05ca5bf1c042ef54c510aadea80000202a2ac02bc02fc02cc030cca9cca8cc14cc13c013c014009c009d002f0035000a01000081dada0000ff010001000000001800160000136c6f63616c686f73742e6461706c69652e6d650017000000230000000d00140012040308040401050308050501080606010201000500050100000000001200000010000e000c02683208687474702f312e3175500000000b00020100000a000a00084a4a001d00170018baba000100';
      writer.write(Buffer.from(sni, 'hex'));
    
      // this "hangs", but it if you attach a `data` event you can see that
      // the "reader" was written back to with the handshake response
    });
  3. addaleax commented on May 15, 2017

    @addaleax
    addaleax
    on May 15, 2017
    Member
    More actions

    I think this has been fixed in b23d414 – can you confirm that?

  4. coolaj86 commented on Jul 28, 2017

    @coolaj86
    coolaj86
    on Jul 28, 2017
    Author
    More actions

    Using the example code that I provided above my findings are:

    FAILURE in node v6.11.1 LTS

    SUCCESS in node v8.2.1

  5. coolaj86
    closed this as completedon Aug 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.