@@ -20,10 +20,11 @@ if (cluster.isMaster) {
2020 let reqCount = 0 ;
2121 let lastSession = null ;
2222 let shootOnce = false ;
23+ let workerPort = null ;
2324
2425 function 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 , {
2728 session : lastSession ,
2829 rejectUnauthorized : false
2930 } , function ( ) {
@@ -42,11 +43,12 @@ if (cluster.isMaster) {
4243
4344 function fork ( ) {
4445 const worker = cluster . fork ( ) ;
45- worker . on ( 'message' , function ( msg ) {
46+ worker . on ( 'message' , function ( { msg, port } ) {
4647 console . error ( '[master] got %j' , msg ) ;
4748 if ( msg === 'reused' ) {
4849 ++ reusedCount ;
4950 } else if ( msg === 'listening' && ! shootOnce ) {
51+ workerPort = port || workerPort ;
5052 shootOnce = true ;
5153 shoot ( ) ;
5254 }
@@ -78,15 +80,19 @@ const options = {
7880
7981const server = tls . createServer ( options , function ( c ) {
8082 if ( 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 }
8587 c . 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