1
0
mirror of https://github.com/ceph/ceph-csi.git synced 2025-06-14 18:53:35 +00:00
Files
.github
assets
charts
cmd
deploy
docs
e2e
examples
internal
scripts
troubleshooting
vendor
github.com
golang.org
gomodules.xyz
google.golang.org
appengine
internal
base
datastore
log
remote_api
urlfetch
api.go
api_classic.go
api_common.go
app_id.go
identity.go
identity_classic.go
identity_flex.go
identity_vm.go
internal.go
main.go
main_common.go
main_vm.go
metadata.go
net.go
regen.sh
transaction.go
urlfetch
LICENSE
genproto
grpc
protobuf
gopkg.in
k8s.io
sigs.k8s.io
modules.txt
.commitlintrc.yml
.gitignore
.mergify.yml
.pre-commit-config.yaml
LICENSE
Makefile
README.md
build.env
deploy.sh
go.mod
go.sum
ceph-csi/vendor/google.golang.org/appengine/internal/net.go
Madhu Rajanna 83559144b1 rebase: update kubernetes to v1.20.0
updated kubernetes packages to latest
release.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
2020-12-17 16:04:54 +00:00

57 lines
1.2 KiB
Go

// Copyright 2014 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package internal
// This file implements a network dialer that limits the number of concurrent connections.
// It is only used for API calls.
import (
"log"
"net"
"runtime"
"sync"
"time"
)
var limitSem = make(chan int, 100) // TODO(dsymonds): Use environment variable.
func limitRelease() {
// non-blocking
select {
case <-limitSem:
default:
// This should not normally happen.
log.Print("appengine: unbalanced limitSem release!")
}
}
func limitDial(network, addr string) (net.Conn, error) {
limitSem <- 1
// Dial with a timeout in case the API host is MIA.
// The connection should normally be very fast.
conn, err := net.DialTimeout(network, addr, 10*time.Second)
if err != nil {
limitRelease()
return nil, err
}
lc := &limitConn{Conn: conn}
runtime.SetFinalizer(lc, (*limitConn).Close) // shouldn't usually be required
return lc, nil
}
type limitConn struct {
close sync.Once
net.Conn
}
func (lc *limitConn) Close() error {
defer lc.close.Do(func() {
limitRelease()
runtime.SetFinalizer(lc, nil)
})
return lc.Conn.Close()
}