Skip to content

Commit

Permalink
add explicit initialization of fields of structures in internal/; log…
Browse files Browse the repository at this point in the history
…/; retry/
  • Loading branch information
kozyrev-m committed May 5, 2024
1 parent 99d28ce commit 299daa4
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 23 deletions.
1 change: 1 addition & 0 deletions internal/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ func (c *conn) NewStream(

s := &grpcClientStream{
parentConn: c,
stream: nil,
streamCtx: ctx,
streamCancel: cancel,
wrapping: useWrapping,
Expand Down
46 changes: 38 additions & 8 deletions internal/credentials/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,14 @@ func (tokenSource *tokenSourceOption) ApplyOauth2CredentialsOption(c *oauth2Toke
func WithSubjectToken(subjectToken TokenSource) *tokenSourceOption {
return &tokenSourceOption{
source: subjectToken,
createFunc: nil,
tokenSourceType: SubjectTokenSourceType,
}
}

func WithFixedSubjectToken(token, tokenType string) *tokenSourceOption {
return &tokenSourceOption{
source: nil,
createFunc: func() (TokenSource, error) {
return NewFixedTokenSource(token, tokenType), nil
},
Expand All @@ -194,6 +196,7 @@ func WithFixedSubjectToken(token, tokenType string) *tokenSourceOption {

func WithJWTSubjectToken(opts ...JWTTokenSourceOption) *tokenSourceOption {
return &tokenSourceOption{
source: nil,
createFunc: func() (TokenSource, error) {
return NewJWTTokenSource(opts...)
},
Expand All @@ -205,12 +208,14 @@ func WithJWTSubjectToken(opts ...JWTTokenSourceOption) *tokenSourceOption {
func WithActorToken(actorToken TokenSource) *tokenSourceOption {
return &tokenSourceOption{
source: actorToken,
createFunc: nil,
tokenSourceType: ActorTokenSourceType,
}
}

func WithFixedActorToken(token, tokenType string) *tokenSourceOption {
return &tokenSourceOption{
source: nil,
createFunc: func() (TokenSource, error) {
return NewFixedTokenSource(token, tokenType), nil
},
Expand All @@ -220,6 +225,7 @@ func WithFixedActorToken(token, tokenType string) *tokenSourceOption {

func WithJWTActorToken(opts ...JWTTokenSourceOption) *tokenSourceOption {
return &tokenSourceOption{
source: nil,
createFunc: func() (TokenSource, error) {
return NewJWTTokenSource(opts...)
},
Expand Down Expand Up @@ -265,10 +271,21 @@ func NewOauth2TokenExchangeCredentials(
opts ...Oauth2TokenExchangeCredentialsOption,
) (*oauth2TokenExchange, error) {
c := &oauth2TokenExchange{
grantType: "urn:ietf:params:oauth:grant-type:token-exchange",
requestedTokenType: "urn:ietf:params:oauth:token-type:access_token",
requestTimeout: defaultRequestTimeout,
sourceInfo: stack.Record(1),
tokenEndpoint: "",
grantType: "urn:ietf:params:oauth:grant-type:token-exchange",
resource: "",
audience: nil,
scope: nil,
requestedTokenType: "urn:ietf:params:oauth:token-type:access_token",
subjectTokenSource: nil,
actorTokenSource: nil,
requestTimeout: defaultRequestTimeout,
receivedToken: "",
updateTokenTime: time.Time{},
receivedTokenExpireTime: time.Time{},
mutex: sync.RWMutex{},
updating: atomic.Bool{},
sourceInfo: stack.Record(1),
}

var err error
Expand Down Expand Up @@ -452,8 +469,10 @@ func (provider *oauth2TokenExchange) exchangeToken(ctx context.Context, now time
req.Close = true

client := http.Client{
Transport: http.DefaultTransport,
Timeout: provider.requestTimeout,
Transport: http.DefaultTransport,
CheckRedirect: nil,
Jar: nil,
Timeout: provider.requestTimeout,
}

result, err := client.Do(req)
Expand Down Expand Up @@ -756,7 +775,14 @@ func WithRSAPrivateKeyPEMFile(path string) *rsaPrivateKeyPemFileOption {

func NewJWTTokenSource(opts ...JWTTokenSourceOption) (*jwtTokenSource, error) {
s := &jwtTokenSource{
tokenTTL: defaultJWTTokenTTL,
signingMethod: nil,
keyID: "",
privateKey: nil,
issuer: "",
subject: "",
audience: nil,
id: "",
tokenTTL: defaultJWTTokenTTL,
}

var err error
Expand Down Expand Up @@ -801,6 +827,8 @@ func (s *jwtTokenSource) Token() (Token, error) {
err error
)
t := jwt.Token{
Raw: "",
Method: s.signingMethod,
Header: map[string]interface{}{
"typ": "JWT",
"alg": s.signingMethod.Alg(),
Expand All @@ -812,9 +840,11 @@ func (s *jwtTokenSource) Token() (Token, error) {
IssuedAt: issued,
Audience: s.audience,
ExpiresAt: expire,
NotBefore: nil,
ID: s.id,
},
Method: s.signingMethod,
Signature: "",
Valid: false,
}

var token Token
Expand Down
1 change: 1 addition & 0 deletions internal/table/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ func renameTables(
operationCancelAfter,
operation.ModeSync,
),
Tables: nil,
}
for _, opt := range opts {
if opt != nil {
Expand Down
25 changes: 13 additions & 12 deletions internal/topic/topicwriterinternal/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,19 @@ type messageQueue struct {

func newMessageQueue() messageQueue {
return messageQueue{
messagesByOrder: make(map[int]messageWithDataContent),
seqNoToOrderID: make(map[int64]int),
hasNewMessages: make(empty.Chan, 1),
closedChan: make(empty.Chan),
lastSeqNo: -1,
OnAckReceived: nil,
closedErr: nil,
acksReceivedEvent: xsync.EventBroadcast{},
m: xsync.RWMutex{RWMutex: sync.RWMutex{}},
closed: false,
lastWrittenIndex: 0,
lastSentIndex: 0,
messagesByOrder: make(map[int]messageWithDataContent),
seqNoToOrderID: make(map[int64]int),
hasNewMessages: make(empty.Chan, 1),
closedChan: make(empty.Chan),
lastSeqNo: -1,
OnAckReceived: nil,
closedErr: nil,
acksReceivedEvent: xsync.EventBroadcast{},
m: xsync.RWMutex{RWMutex: sync.RWMutex{}},
stopReceiveMessagesReason: nil,
closed: false,
lastWrittenIndex: 0,
lastSentIndex: 0,
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/xcontext/cancels_quard.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type (

func NewCancelsGuard() *CancelsGuard {
return &CancelsGuard{
mu: sync.Mutex{},
cancels: make(map[*context.CancelFunc]struct{}),
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/xsql/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func Open(parent ydbDriver, opts ...ConnectorOption) (_ *Connector, err error) {
pathNormalizer: bind.TablePathPrefix(parent.Name()),
trace: nil,
traceRetry: nil,
retryBudget: nil,
}
for _, opt := range opts {
if opt != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/xsync/last_usage_guard.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func WithClock(clock clockwork.Clock) lastUsageOption {

func NewLastUsage(opts ...lastUsageOption) *lastUsage {
lastUsage := &lastUsage{
locks: atomic.Int64{},
t: atomic.Pointer[time.Time]{},
clock: clockwork.NewRealClock(),
}
for _, opt := range opts {
Expand Down
1 change: 1 addition & 0 deletions log/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,5 +503,6 @@ func internalDriver(l Logger, d trace.Detailer) trace.Driver { //nolint:gocyclo
OnPoolRelease: nil,
OnConnPark: nil,
OnBalancerClusterDiscoveryAttempt: nil,
OnConnStreamFinish: nil,
}
}
6 changes: 4 additions & 2 deletions retry/budget/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ func withFixedBudgetClock(clock clockwork.Clock) fixedBudgetOption {
// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
func Limited(attemptsPerSecond int, opts ...fixedBudgetOption) *fixedBudget {
q := &fixedBudget{
clock: clockwork.NewRealClock(),
done: make(chan struct{}),
clock: clockwork.NewRealClock(),
ticker: nil,
quota: nil,
done: make(chan struct{}),
}
for _, opt := range opts {
opt(q)
Expand Down
2 changes: 1 addition & 1 deletion retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func WithTrace(t *trace.Retry) traceOption {
return traceOption{t: t}
}

var _ Option = budgetOption{}
var _ Option = budgetOption{b: nil}

type budgetOption struct {
b budget.Budget
Expand Down

0 comments on commit 299daa4

Please sign in to comment.