Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Already buffered data when creating a TLSSocket doesn't trigger/throw 'error' #9355

Closed
jameshartig opened this issue Mar 8, 2015 · 1 comment
Labels

Comments

@jameshartig
Copy link

If you pass a socket with already buffered data to TLSSocket and there's an error like:

[Error: 139745410942944:error:1408A0C1:SSL routines:SSL3_GET_CLIENT_HELLO:no shared cipher:s3_srvr.c:1352]

It will fire as a _tlsError immediately while in the constructor instead of either throwing an error (if there were no error handlers) or waiting till the next tick to fire the _tlsError.

This can be solved by wrapping this._init(socket) in a process.nextTick or delaying:

  // Socket already has some buffered data - emulate receiving it
  if (socket && socket._readableState.length) {
    var buf;
    while ((buf = socket.read()) !== null)
      this.ssl.receive(buf);
  }

A third option could also be to not immediately add an error listener in the constructor.

It seems like the second option (delaying the initial buffer read) is better but let me know what you guys think.

@jameshartig
Copy link
Author

It looks like actually the error is coming through this.ssl.onerror instead of actually firing an error event so the third option won't work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants