oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.13k stars 2.67k forks source link

`servers.listeners('connection')` should not be empty array in `tls.createServer()` #13490

Open kenzuya opened 3 weeks ago

kenzuya commented 3 weeks ago

What version of Bun is running?

1.1.25+fe62a6140

What platform is your computer?

Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

import tls from 'node:tls';

const server = tls.createServer()
console.log(server.listeners('connection'))

What is the expected behavior?

[ [Function: tlsConnectionListener] ]

What do you see instead?

[] // empty array

Additional information

because of the empty array I can't use the mockttp module

here is an example code to use the mockttp module

import mockServer from 'mockttp'

const proxy = mockServer.getLocal()

proxy.start(8000) // this is throw error
cirospaciari commented 3 weeks ago

tlsConnectionListener is a non documented implementation detail in Node.js, Bun dont wrap the net socket in a JS Layer like Node.js.

This makes some assumptions that are not true in Bun: https://github.com/httptoolkit/mockttp/blob/4bbab59e174f000cf1d00256a6fbcb7501b8346b/src/server/http-combo-server.ts#L388-L423

  1. Bun dont wrap the socket in javascript side to upgrade the socket.
  2. Not calling the first connection listener will not prevent the socket of doing the TLS upgrade.