@@ -41,10 +41,11 @@ if (cluster.isMaster) {
41
41
let reqCount = 0 ;
42
42
let lastSession = null ;
43
43
let shootOnce = false ;
44
+ let workerPort = null ;
44
45
45
46
function shoot ( ) {
46
- console . error ( '[master] connecting' ) ;
47
- const c = tls . connect ( common . PORT , {
47
+ console . error ( '[master] connecting' , workerPort ) ;
48
+ const c = tls . connect ( workerPort , {
48
49
session : lastSession ,
49
50
rejectUnauthorized : false
50
51
} , function ( ) {
@@ -63,11 +64,12 @@ if (cluster.isMaster) {
63
64
64
65
function fork ( ) {
65
66
const worker = cluster . fork ( ) ;
66
- worker . on ( 'message' , function ( msg ) {
67
+ worker . on ( 'message' , function ( { msg, port } ) {
67
68
console . error ( '[master] got %j' , msg ) ;
68
69
if ( msg === 'reused' ) {
69
70
++ reusedCount ;
70
71
} else if ( msg === 'listening' && ! shootOnce ) {
72
+ workerPort = port || workerPort ;
71
73
shootOnce = true ;
72
74
shoot ( ) ;
73
75
}
@@ -99,15 +101,19 @@ const options = {
99
101
100
102
const server = tls . createServer ( options , function ( c ) {
101
103
if ( c . isSessionReused ( ) ) {
102
- process . send ( 'reused' ) ;
104
+ process . send ( { msg : 'reused' } ) ;
103
105
} else {
104
- process . send ( 'not-reused' ) ;
106
+ process . send ( { msg : 'not-reused' } ) ;
105
107
}
106
108
c . end ( ) ;
107
109
} ) ;
108
110
109
- server . listen ( common . PORT , function ( ) {
110
- process . send ( 'listening' ) ;
111
+ server . listen ( 0 , function ( ) {
112
+ const { port } = server . address ( ) ;
113
+ process . send ( {
114
+ msg : 'listening' ,
115
+ port,
116
+ } ) ;
111
117
} ) ;
112
118
113
119
process . on ( 'message' , function listener ( msg ) {
0 commit comments