Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/ateapi/internal/controlapi/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ func NewAteletDialer(workerIndexer cache.Indexer, ateletIndexer cache.Indexer) *
return &AteletDialer{
workerIndexer: workerIndexer,
ateletIndexer: ateletIndexer,
ateletConns: lru.New(1024),
ateletConns: lru.NewWithEvictionFunc(1024, func(key lru.Key, value any) {
// Close connection when evicting from cache.
conn, ok := value.(*grpc.ClientConn)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we log when either the assertion or Close() fails?

if ok {
conn.Close()
}
}),
}
}

Expand Down
9 changes: 8 additions & 1 deletion cmd/atelet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ func main() {
go serverboot.StartMetricsServer(ctx, serverboot.MetricsServerOptions{Addr: *metricsListenAddr})

ateomDialer := &AteomDialer{
conns: lru.New(256),
conns: lru.NewWithEvictionFunc(256, func(key lru.Key, value any) {
// Close connection when evicting from cache.
conn, ok := value.(*grpc.ClientConn)
if ok {
conn.Close()
Comment thread
ericdbishop marked this conversation as resolved.
Outdated
}
}),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming this looks ok, not sure if there is a common util file I could move this function to so it's not duplicated across files.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we blindly close on eviction, can this close a connection which is already in use?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, how long lived are these connections? Maybe a delayed close might help? I also was considering if we should make the cache size configurable for both dialers.

}

var gcpRegistryAuthn authn.Authenticator
Expand Down Expand Up @@ -806,6 +812,7 @@ func toAteomReadyz(in *ateletpb.Readyz) *ateompb.Readyz {
return out
}

// AteomDialer handles gRPC connections to Ateom pods.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had just seen a similar comment in the ateapi file: https://github.com/ericdbishop/substrate/blob/5b11a10073e97f0c425bb7bee23955b2d5762dc3/cmd/ateapi/internal/controlapi/dialer.go#L31. I could remove it if preferred.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries just curious

type AteomDialer struct {
conns *lru.Cache
}
Expand Down