diff --git a/src/pcap/api.go b/src/pcap/api.go index 092c3163..5a4e1188 100644 --- a/src/pcap/api.go +++ b/src/pcap/api.go @@ -28,14 +28,14 @@ type API struct { // id of the instance where the api is located. id string - maxConcurrentCaptures uint - concurrentStreams atomic.Int32 + maxConcurrentCaptures uint32 + concurrentStreams atomic.Uint32 tlsCredentials credentials.TransportCredentials UnimplementedAPIServer } -func NewAPI(bufConf BufferConf, clientTLS *ClientTLS, id string, maxConcurrentCaptures uint) (*API, error) { +func NewAPI(bufConf BufferConf, clientTLS *ClientTLS, id string, maxConcurrentCaptures uint32) (*API, error) { clientTLSCreds := insecure.NewCredentials() if clientTLS != nil { clientTLSConf, err := clientTLS.Config() @@ -180,9 +180,9 @@ func (api *API) Capture(stream API_CaptureServer) (err error) { currentStreams := api.concurrentStreams.Add(1) - defer api.concurrentStreams.Add(-1) + defer api.concurrentStreams.Add(^uint32(0)) // subtract 1 by adding binary complement of 0 - if currentStreams > int32(api.maxConcurrentCaptures) { + if currentStreams > api.maxConcurrentCaptures { vcapID, ok := ctx.Value(HeaderVcapID).(string) if !ok { return errorf(codes.ResourceExhausted, "failed starting capture: %w", errTooManyCaptures) diff --git a/src/pcap/cmd/pcap-api/config.go b/src/pcap/cmd/pcap-api/config.go index f8067474..7e5cb18e 100644 --- a/src/pcap/cmd/pcap-api/config.go +++ b/src/pcap/cmd/pcap-api/config.go @@ -30,7 +30,7 @@ var DefaultAPIConfig = APIConfig{ type APIConfig struct { pcap.NodeConfig `yaml:"-,inline"` AgentsMTLS *pcap.ClientTLS `yaml:"agents_mtls" validate:"omitempty"` - ConcurrentCaptures uint `yaml:"concurrent_captures"` + ConcurrentCaptures uint32 `yaml:"concurrent_captures"` DrainTimeout time.Duration `yaml:"drain_timeout"` BoshResolverConfig *pcap.BoshResolverConfig `yaml:"bosh,omitempty" validate:"dive"` diff --git a/src/pcap/test/integration/agent_api_client.go b/src/pcap/test/integration/agent_api_client.go index 23d3bf2d..c2dfe452 100644 --- a/src/pcap/test/integration/agent_api_client.go +++ b/src/pcap/test/integration/agent_api_client.go @@ -21,7 +21,7 @@ import ( var apiClient pcap.APIClient -var MaxConcurrentCaptures uint = 2 +var MaxConcurrentCaptures uint32 = 2 // port is used for creating agents. var port = 9494