Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

cannot pass TLSSocket to child process #865

Closed
endel opened this issue Oct 7, 2017 · 7 comments
Closed

cannot pass TLSSocket to child process #865

endel opened this issue Oct 7, 2017 · 7 comments

Comments

@endel
Copy link

endel commented Oct 7, 2017

  • Node.js Version: 8.6.0
  • OS: OSX

How can I pass a TLSSocket to a child process? (created from "https" module)

I'm having this issue:

internal/child_process.js:630
        throw new errors.TypeError('ERR_INVALID_HANDLE_TYPE');
        ^

TypeError [ERR_INVALID_HANDLE_TYPE]: This handle type cannot be sent

Pseudo-code:

httpsServer.on('request', (request, response) => {
  let socket = request.connection;
  myChildProcess.send({}, socket);
})

This works fine using "http" module. The error happens only when using "https".

Thanks in advance.

@bnoordhuis
Copy link
Member

You can't, TLSSockets have process-specific state.

What you can do is transfer the net.Socket instance before the TLS handshake is initiated: start a normal net.Server in process A, send socket to process B, call new TLSSocket(socket) in B.

@endel
Copy link
Author

endel commented Oct 8, 2017

Thanks @bnoordhuis, do you know which event can I get the net.Socket from? Perhaps it's possible to get a net.Socket instance from the TLSSocket?

@bnoordhuis
Copy link
Member

You mean in process B? process.on('message', (msg, handle) => { /* ... */ }). The cluster and child_process reference documentation has more info.

Perhaps it's possible to get a net.Socket instance from the TLSSocket?

That wouldn't do any good. Once the TLS handshake starts, it's too late.

@endel
Copy link
Author

endel commented Oct 13, 2017

@bnoordhuis actually, you mentioned that's possible to get the net.Socket before the TLS handshake. I'm wondering which event exactly is before TLS handshake where I can get the net.Socket from? Thanks!

@bnoordhuis
Copy link
Member

The key point is that you start a plain TCP server (no TLS) in process A. An incoming connection is handed off to process B which wraps it in a TLSSocket and initiates the handshake.

@lahsenifl
Copy link

What you can do is transfer the net.Socket instance before the TLS handshake is initiated: start a normal net.Server in process A, send socket to process B, call new TLSSocket(socket) in B.
@bnoordhuis can you provide example for this?

@ackava
Copy link

ackava commented Sep 20, 2024

In theory it is possible, as TLS Socket has ability to do session resumption.

  1. In Process A Set pauseOnConnect to true, once TLS Socket is initialized
  2. Unwrap socket and collect session buffer (which contains SSL Certificate and some other information)
  3. Send session buffer to Process B
  4. Send plain socket to Process B
  5. In Process B Initialize new TLS Socket from plain socket and pass session in a constructor of TLS Socket to resume the SSL session

However, unless node makes this process easier, it is little difficult to get it working.

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

No branches or pull requests

4 participants