@@ -49,7 +49,8 @@ func startListenRPCAndSQL(
49
49
) (
50
50
sqlListener net.Listener ,
51
51
pgLoopbackListener * netutil.LoopbackListener ,
52
- rpcLoopbackDial func (context.Context ) (net.Conn , error ),
52
+ grpcLoopbackDial func (context.Context ) (net.Conn , error ),
53
+ drpcLoopbackDial func (context.Context ) (net.Conn , error ),
53
54
startRPCServer func (ctx context.Context ),
54
55
err error ,
55
56
) {
@@ -66,7 +67,7 @@ func startListenRPCAndSQL(
66
67
var err error
67
68
ln , err = rpcListenerFactory (ctx , & cfg .Addr , & cfg .AdvertiseAddr , rpcChanName , acceptProxyProtocolHeaders )
68
69
if err != nil {
69
- return nil , nil , nil , nil , err
70
+ return nil , nil , nil , nil , nil , err
70
71
}
71
72
log .Eventf (ctx , "listening on port %s" , cfg .Addr )
72
73
}
@@ -79,7 +80,7 @@ func startListenRPCAndSQL(
79
80
pgL = cfg .SQLAddrListener
80
81
}
81
82
if err != nil {
82
- return nil , nil , nil , nil , err
83
+ return nil , nil , nil , nil , nil , err
83
84
}
84
85
// The SQL listener shutdown worker, which closes everything under
85
86
// the SQL port when the stopper indicates we are shutting down.
@@ -95,7 +96,7 @@ func startListenRPCAndSQL(
95
96
}
96
97
if err := stopper .RunAsyncTask (workersCtx , "wait-quiesce" , waitQuiesce ); err != nil {
97
98
waitQuiesce (workersCtx )
98
- return nil , nil , nil , nil , err
99
+ return nil , nil , nil , nil , nil , err
99
100
}
100
101
log .Eventf (ctx , "listening on sql port %s" , cfg .SQLAddr )
101
102
}
@@ -129,7 +130,7 @@ func startListenRPCAndSQL(
129
130
// Then we update the advertised addr with the right port, if
130
131
// the port had been auto-allocated.
131
132
if err := UpdateAddrs (ctx , & cfg .SQLAddr , & cfg .SQLAdvertiseAddr , ln .Addr ()); err != nil {
132
- return nil , nil , nil , nil , errors .Wrapf (err , "internal error" )
133
+ return nil , nil , nil , nil , nil , errors .Wrapf (err , "internal error" )
133
134
}
134
135
}
135
136
@@ -158,18 +159,22 @@ func startListenRPCAndSQL(
158
159
}
159
160
}
160
161
161
- rpcLoopbackL := netutil .NewLoopbackListener (ctx , stopper )
162
+ grpcLoopbackL := netutil .NewLoopbackListener (ctx , stopper )
162
163
sqlLoopbackL := netutil .NewLoopbackListener (ctx , stopper )
163
164
drpcCtx , drpcCancel := context .WithCancel (workersCtx )
165
+ // Create a dedicated DRPC loopback listener. Since this listener is exclusively for DRPC,
166
+ // no protocol header inspection is needed.
167
+ drpcLoopbackL := netutil .NewLoopbackListener (ctx , stopper )
164
168
165
169
// The remainder shutdown worker.
166
170
waitForQuiesce := func (context.Context ) {
167
171
<- stopper .ShouldQuiesce ()
168
172
drpcCancel ()
169
173
// TODO(bdarnell): Do we need to also close the other listeners?
170
174
netutil .FatalIfUnexpected (grpcL .Close ())
171
- netutil .FatalIfUnexpected (drpcL .Close ())
172
- netutil .FatalIfUnexpected (rpcLoopbackL .Close ())
175
+ netutil .FatalIfUnexpected (grpcLoopbackL .Close ())
176
+ netutil .FatalIfUnexpected (drpcL .Close ()) // Closing this listener is as good as closing drpcTLSL
177
+ netutil .FatalIfUnexpected (drpcLoopbackL .Close ()) // Closing this listener is as good as closing drpcLoopbackTLSL
173
178
netutil .FatalIfUnexpected (sqlLoopbackL .Close ())
174
179
netutil .FatalIfUnexpected (ln .Close ())
175
180
}
@@ -191,7 +196,7 @@ func startListenRPCAndSQL(
191
196
waitForQuiesce (ctx )
192
197
stopGRPC ()
193
198
drpcCancel ()
194
- return nil , nil , nil , nil , err
199
+ return nil , nil , nil , nil , nil , err
195
200
}
196
201
stopper .AddCloser (stop .CloserFn (stopGRPC ))
197
202
@@ -213,7 +218,15 @@ func startListenRPCAndSQL(
213
218
}
214
219
})
215
220
_ = stopper .RunAsyncTask (workersCtx , "serve-loopback-grpc" , func (context.Context ) {
216
- netutil .FatalIfUnexpected (grpc .Serve (rpcLoopbackL ))
221
+ netutil .FatalIfUnexpected (grpc .Serve (grpcLoopbackL ))
222
+ })
223
+ _ = stopper .RunAsyncTask (workersCtx , "serve-loopback-drpc" , func (context.Context ) {
224
+ if cfg := drpc .tlsCfg ; cfg != nil {
225
+ drpcdrpcLoopbackTLSL := tls .NewListener (drpcLoopbackL , cfg )
226
+ netutil .FatalIfUnexpected (drpc .Serve (ctx , drpcdrpcLoopbackTLSL ))
227
+ } else {
228
+ netutil .FatalIfUnexpected (drpc .Serve (ctx , drpcLoopbackL ))
229
+ }
217
230
})
218
231
219
232
_ = stopper .RunAsyncTask (ctx , "serve-mux" , func (context.Context ) {
@@ -223,5 +236,5 @@ func startListenRPCAndSQL(
223
236
})
224
237
}
225
238
226
- return pgL , sqlLoopbackL , rpcLoopbackL .Connect , startRPCServer , nil
239
+ return pgL , sqlLoopbackL , grpcLoopbackL . Connect , drpcLoopbackL .Connect , startRPCServer , nil
227
240
}
0 commit comments