func (p *Proxy) Serve(ctx context.Context) error {
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	p.cancel = cancel
	p.cfg.WebTLSConfig.NextProtos = common.ProtocolsToString(p.supportedProtocols)
	for {
		clientConn, err := p.cfg.Listener.Accept()
		if err != nil {
			if utils.IsOKNetworkError(err) || trace.IsConnectionProblem(err) {
				return nil
			}
			return trace.Wrap(err)
		}
		go func() {
			// In case of successful handleConn call leave the connection Close() call up to service handler.
			// For example in ReverseTunnel handles connection asynchronously and closing conn after
			// service handler returned will break service logic.
			// https://github.com/gravitational/teleport/blob/master/lib/sshutils/server.go#L397
			if err := p.handleConn(ctx, clientConn); err != nil {
				if cerr := clientConn.Close(); cerr != nil && !utils.IsOKNetworkError(cerr) {
					p.log.WithError(cerr).Warnf("Failed to close client connection.")
				}

				if trace.IsBadParameter(err) {
					p.log.Warnf("Failed to handle client connection: %v", err)
				} else if !utils.IsOKNetworkError(err) {
					p.log.WithError(err).Warnf("Failed to handle client connection.")
				}
			}
		}()
	}
}
// Serve starts accepting connections.
Serve starts accepting connections.
// Serve starts accepting connections .
func (p *Proxy) Serve(ctx context.Context) error {
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	p.cancel = cancel
	p.cfg.WebTLSConfig.NextProtos = common.ProtocolsToString(p.supportedProtocols)
	for {
		clientConn, err := p.cfg.Listener.Accept()
		if err != nil {
			if utils.IsOKNetworkError(err) || trace.IsConnectionProblem(err) {
				return nil
			}
			return trace.Wrap(err)
		}
		go func() {
			if err := p.handleConn(ctx, clientConn); err != nil {
				if cerr := clientConn.Close(); cerr != nil && !utils.IsOKNetworkError(cerr) {
					p.log.WithError(cerr).Warnf("Failed to close client connection.")
				}
				if trace.IsBadParameter(err) {
					p.log.Warnf("Failed to handle client connection: %v", err)
				} else if !utils.IsOKNetworkError(err) {
					p.log.WithError(err).Warnf("Failed to handle client connection.")
				}
			}
		}()
	}
}
func ( p * Proxy ) Serve ( ctx context . Context ) error { ctx , cancel := context . WithCancel ( ctx ) defer cancel ( ) p . cancel = cancel p . cfg . WebTLSConfig . NextProtos = common . ProtocolsToString ( p . supportedProtocols ) for { clientConn , err := p . cfg . Listener . Accept ( ) if err != nil { if utils . IsOKNetworkError ( err ) || trace . IsConnectionProblem ( err ) { return nil } return trace . Wrap ( err ) } go func ( ) { if err := p . handleConn ( ctx , clientConn ) ; err != nil { if cerr := clientConn . Close ( ) ; cerr != nil && ! utils . IsOKNetworkError ( cerr ) { p . log . WithError ( cerr ) . Warnf ( " " ) } if trace . IsBadParameter ( err ) { p . log . Warnf ( " " , err ) } else if ! utils . IsOKNetworkError ( err ) { p . log . WithError ( err ) . Warnf ( " " ) } } } ( ) } }
Serve starts accepting connections.
Serve starts accepting connections .
// In case of successful handleConn call leave the connection Close() call up to service handler. // For example in ReverseTunnel handles connection asynchronously and closing conn after // service handler returned will break service logic. // https://github.com/gravitational/teleport/blob/master/lib/sshutils/server.go#L397