rpc: proper handling of context cancellation for transportmux + dataconn

- prior to this patch, context cancellation would leave rpc.Server open
- did not make problems because context was only cancelled by SIGINT,
  which was immediately followed by os.Exit
This commit is contained in:
Christian Schwarz
2020-04-20 21:24:42 +02:00
parent 28e66ca78f
commit 3d91686350
5 changed files with 107 additions and 26 deletions
+6
View File
@@ -65,6 +65,12 @@ type TCPAuthListener struct {
}
func (f *TCPAuthListener) Accept(ctx context.Context) (*transport.AuthConn, error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
go func() {
<-ctx.Done()
cancel()
}()
nc, err := f.TCPListener.AcceptTCP()
if err != nil {
return nil, err