-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: track opened grpc connections
This is an alternative to #10283 which doesn't close the connections and instead allows us to easily track the lost grpc connections using pprof. Fix various grpc leaks while we are at it. Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
- Loading branch information
Showing
6 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package client_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"runtime" | ||
"runtime/pprof" | ||
"time" | ||
|
||
"github.com/siderolabs/gen/ensure" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
"github.com/siderolabs/talos/pkg/machinery/client" | ||
) | ||
|
||
func ExampleNew() { | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
|
||
connPprof := pprof.Lookup("machinery/client/grpc.grpcConn") | ||
if connPprof == nil { | ||
panic(errors.New("profile machinery/client/grpc.grpcConn not found")) | ||
} | ||
|
||
fmt.Println("before:", connPprof.Count()) | ||
|
||
c := ensure.Value( | ||
client.New( | ||
ctx, | ||
client.WithUnixSocket("/path/to/socket"), | ||
client.WithGRPCDialOptions( | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
), | ||
), | ||
) | ||
|
||
fmt.Println("after client.New :", connPprof.Count()) | ||
|
||
if err := c.Close(); err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println("after client.Close:", connPprof.Count()) | ||
|
||
c2 := ensure.Value( | ||
client.New( | ||
ctx, | ||
client.WithUnixSocket("/path/to/socket"), | ||
client.WithGRPCDialOptions( | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
), | ||
), | ||
) | ||
|
||
fmt.Println("after client.New 2:", connPprof.Count()) | ||
|
||
_ = c2 | ||
|
||
runtime.GC() | ||
|
||
fmt.Println("after gc:", connPprof.Count()) | ||
|
||
// Output: | ||
// before: 0 | ||
// after client.New : 1 | ||
// after client.Close: 0 | ||
// after client.New 2: 1 | ||
// after gc: 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters