knative / eventing-contrib

Event Sources
Apache License 2.0
224 stars 225 forks source link

nethttp.Client should have the default no zero arg about connect #1677

Closed obailiumingo closed 3 years ago

obailiumingo commented 3 years ago

Describe the bug when I use kafkaSource to consume kafka message for several minutes, I get an error log {"level":"info","ts":"2021-01-11T06:42:19.382Z","caller":"kafka/consumer_handler.go:83","msg":"Failure while handling a message","topic":"log","partition":0,"offset":5355394,"error":"Post \"http://functionef79f344e6a1a40c.1f1d12e7f824c594-szdev.svc.cluster.local\": dial tcp 10.108.87.146:80: connect: cannot assign requested address"}

10.108.87.146:80 is istio cluster-local-gateway then I user ‘nstner’ command to get into container, I found there are more than 20,000 connection with “ESTABLISHED” status.

when I read kafkaSource code, I think mybe it is caused by the error config about nethttp.Client

src\knative.dev\eventing-contrib\vendor\knative.dev\eventing\pkg\adapter\v2\main_message.go(113) httpBindingsSender, err := kncloudevents.NewHttpMessageSender(nil, env.GetSink())

/src/knative.dev/eventing-contrib/vendor/knative.dev/eventing/pkg/kncloudevents/message_sender.go

func NewHttpMessageSender(connectionArgs *ConnectionArgs, target string) (*HttpMessageSender, error) {
    // Add connection options to the default transport.
    var base = nethttp.DefaultTransport.(*nethttp.Transport).Clone()
    connectionArgs.ConfigureTransport(base)
    // Add output tracing.
    client := &nethttp.Client{
        Transport: &ochttp.Transport{
            Base:        base,
            Propagation: tracecontextb3.TraceContextEgress,
        },
    }

    return &HttpMessageSender{Client: client, Target: target}, nil
}

adapter give an null args , then nethttp.Client use an Transport params with zero value as shown bellow

    // MaxIdleConns controls the maximum number of idle (keep-alive)
    // connections across all hosts. Zero means no limit.
    MaxIdleConns int

    // MaxIdleConnsPerHost, if non-zero, controls the maximum idle
    // (keep-alive) connections to keep per-host. If zero,
    // DefaultMaxIdleConnsPerHost is used.
    MaxIdleConnsPerHost int

    // MaxConnsPerHost optionally limits the total number of
    // connections per host, including connections in the dialing,
    // active, and idle states. On limit violation, dials will block.
    //
    // Zero means no limit.
    MaxConnsPerHost int

knative version 0.15