Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock IAMClient requests when connection lost #186

Conversation

mykola-kobets-epam
Copy link
Contributor

No description provided.

Signed-off-by: Mykola Kobets <mykola_kobets@epam.com>
Only grpc calls required to be locked, streams are wrapped by the
corresponding clients

Signed-off-by: Mykola Kobets <mykola_kobets@epam.com>
@mykola-kobets-epam mykola-kobets-epam force-pushed the iamclient-lock-requests-on-reconnection branch 2 times, most recently from 773ba70 to 9214832 Compare January 17, 2025 17:16
"google.golang.org/grpc"
)

/***********************************************************************************************************************
Copy link
Member

Choose a reason for hiding this comment

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

Are these empty sections (consts,types) needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, removed.

* Public
**********************************************************************************************************************/

// New creates new certificate provider instance.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// New creates new certificate provider instance.
// NewCertProvider creates new certificate provider instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -34,7 +33,6 @@ import (
// CertProvider certificate provider interface.
type CertProvider interface {
GetCertificate(certType string, issuer []byte, serial string) (certURL, keyURL string, err error)
SubscribeCertChanged(certType string) (<-chan *iamanager.CertInfo, error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why it is removed? Not required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, Interface used by Create(M)TLSCredentials, they dont require Subscribe method

@@ -35,6 +35,7 @@ type GRPCConn struct {
sync.Mutex

grpcConn *grpc.ClientConn
started bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix commit message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
client.publicConnection.Set(publicConn)

defer func() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Usually, no need to put good path into defer for readability reason.

Suggested change
defer func() {
defer func() {
if err != nil {
publicConn.Close()
}
}
...
client.publicConnection.Start()

Copy link
Contributor Author

@mykola-kobets-epam mykola-kobets-epam Feb 3, 2025

Choose a reason for hiding this comment

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

client.publicConnection.Start should be done in the end of the function execution to ensure connection succeded. Otherwise we unlock pending requests earlier & they can fail.
Current function beside error check has also
(client.isProtectedConnEnabled) logic, which means we should duplicate
client.publicConnection.Start() in
if (!client.isProtectedConnEnabled) {

}
and in the end of the function.

In order to avoid that I decided to add both cases to defer() function.

if err != nil {
return aoserrors.Wrap(err)
}

client.protectedConnection.Set(protectedConn)

defer func() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for unification maded the same way as for the public connection

Updating grpc connection shouldn't unlock requests.

Signed-off-by: Mykola Kobets <mykola_kobets@epam.com>
Signed-off-by: Mykola Kobets <mykola_kobets@epam.com>
@mykola-kobets-epam mykola-kobets-epam force-pushed the iamclient-lock-requests-on-reconnection branch from 9214832 to 26bfefe Compare February 3, 2025 10:38
Copy link

sonarqubecloud bot commented Feb 3, 2025

@al1img al1img merged commit 0c0bb9d into aosedge:develop Feb 3, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants