Skip to content

Commit 5278b2e

Browse files
Fix some unhandled deferred errors in ./common/ (#3750)
1 parent 930a5e8 commit 5278b2e

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

common/authorization/default_token_key_provider.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"time"
3636

3737
"github.com/golang-jwt/jwt/v4"
38+
"go.uber.org/multierr"
3839
"gopkg.in/square/go-jose.v2"
3940

4041
"go.temporal.io/server/common/config"
@@ -160,13 +161,15 @@ func (a *defaultTokenKeyProvider) updateKeysFromURI(
160161
uri string,
161162
rsaKeys map[string]*rsa.PublicKey,
162163
ecKeys map[string]*ecdsa.PublicKey,
163-
) error {
164+
) (err error) {
164165

165166
resp, err := http.Get(uri)
166167
if err != nil {
167168
return err
168169
}
169-
defer resp.Body.Close()
170+
defer func() {
171+
err = multierr.Combine(err, resp.Body.Close())
172+
}()
170173

171174
jwks := jose.JSONWebKeySet{}
172175
err = json.NewDecoder(resp.Body).Decode(&jwks)

common/log/zap_logger_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestDefaultLogger(t *testing.T) {
120120
logger.With(tag.Error(fmt.Errorf("test error"))).Info("test info", tag.WorkflowActionWorkflowStarted)
121121

122122
// back to normal state
123-
w.Close()
123+
require.Nil(t, w.Close())
124124
os.Stdout = old // restoring the real stdout
125125
out := <-outC
126126
sps := strings.Split(preCaller, ":")
@@ -150,7 +150,7 @@ func TestThrottleLogger(t *testing.T) {
150150
With(With(logger, tag.Error(fmt.Errorf("test error"))), tag.ComponentShardContext).Info("test info", tag.WorkflowActionWorkflowStarted)
151151

152152
// back to normal state
153-
w.Close()
153+
require.Nil(t, w.Close())
154154
os.Stdout = old // restoring the real stdout
155155
out := <-outC
156156
sps := strings.Split(preCaller, ":")
@@ -179,7 +179,7 @@ func TestEmptyMsg(t *testing.T) {
179179
logger.With(tag.Error(fmt.Errorf("test error"))).Info("", tag.WorkflowActionWorkflowStarted)
180180

181181
// back to normal state
182-
w.Close()
182+
require.Nil(t, w.Close())
183183
os.Stdout = old // restoring the real stdout
184184
out := <-outC
185185
sps := strings.Split(preCaller, ":")

0 commit comments

Comments
 (0)