@@ -20,10 +20,11 @@ if (cluster.isMaster) {
2020let reqCount = 0 ;
2121let lastSession = null ;
2222let shootOnce = false ;
23+ let workerPort = null ;
2324
2425function shoot ( ) {
25- console . error ( '[master] connecting' ) ;
26- const c = tls . connect ( common . PORT , {
26+ console . error ( '[master] connecting' , workerPort ) ;
27+ const c = tls . connect ( workerPort , {
2728session : lastSession ,
2829rejectUnauthorized : false
2930} , function ( ) {
@@ -42,11 +43,12 @@ if (cluster.isMaster) {
4243
4344function fork ( ) {
4445const worker = cluster . fork ( ) ;
45- worker . on ( 'message' , function ( msg ) {
46+ worker . on ( 'message' , function ( { msg, port } ) {
4647console . error ( '[master] got %j' , msg ) ;
4748if ( msg === 'reused' ) {
4849++ reusedCount ;
4950} else if ( msg === 'listening' && ! shootOnce ) {
51+ workerPort = port || workerPort ;
5052shootOnce = true ;
5153shoot ( ) ;
5254}
@@ -78,15 +80,19 @@ const options = {
7880
7981const server = tls . createServer ( options , function ( c ) {
8082if ( c . isSessionReused ( ) ) {
81- process . send ( 'reused' ) ;
83+ process . send ( { msg : 'reused' } ) ;
8284} else {
83- process . send ( 'not-reused' ) ;
85+ process . send ( { msg : 'not-reused' } ) ;
8486}
8587c . end ( ) ;
8688} ) ;
8789
88- server . listen ( common . PORT , function ( ) {
89- process . send ( 'listening' ) ;
90+ server . listen ( 0 , function ( ) {
91+ const { port } = server . address ( ) ;
92+ process . send ( {
93+ msg : 'listening' ,
94+ port,
95+ } ) ;
9096} ) ;
9197
9298process . on ( 'message' , function listener ( msg ) {
0 commit comments