27
27
)
28
28
29
29
var (
30
- temporaryCredCacheLock sync.RWMutex
30
+ credCacheLock sync.RWMutex
31
31
)
32
32
33
33
func createCredentialCacheDir () {
@@ -175,9 +175,9 @@ func deleteCredential(sc *snowflakeConn, credType string) {
175
175
// Reads temporary credential file when OS is Linux.
176
176
func readTemporaryCredential (sc * snowflakeConn , credType string ) string {
177
177
target := convertTarget (sc .cfg .Host , sc .cfg .User , credType )
178
- temporaryCredCacheLock .RLock ()
178
+ credCacheLock .Lock ()
179
+ defer credCacheLock .Unlock ()
179
180
localCredCache := readTemporaryCacheFile ()
180
- temporaryCredCacheLock .RUnlock ()
181
181
cred := localCredCache [target ]
182
182
if cred != "" {
183
183
logger .Debug ("Successfully read token. Returning as string" )
@@ -190,30 +190,32 @@ func readTemporaryCredential(sc *snowflakeConn, credType string) string {
190
190
// Writes to temporary credential file when OS is Linux.
191
191
func writeTemporaryCredential (sc * snowflakeConn , credType , token string ) {
192
192
target := convertTarget (sc .cfg .Host , sc .cfg .User , credType )
193
+ credCacheLock .Lock ()
194
+ defer credCacheLock .Unlock ()
193
195
localCredCache [target ] = token
194
196
195
197
j , err := json .Marshal (localCredCache )
196
198
if err != nil {
197
- logger .Debugf ("failed to convert credential to JSON." )
199
+ logger .Warnf ("failed to convert credential to JSON." )
200
+ return
198
201
}
199
- temporaryCredCacheLock .Lock ()
200
202
writeTemporaryCacheFile (j )
201
- temporaryCredCacheLock .Unlock ()
202
203
}
203
204
204
205
func deleteTemporaryCredential (sc * snowflakeConn , credType string ) {
205
206
if credCacheDir == "" {
206
207
logger .Debug ("Cache file doesn't exist. Skipping deleting credential file." )
207
208
} else {
209
+ credCacheLock .Lock ()
210
+ defer credCacheLock .Unlock ()
208
211
target := convertTarget (sc .cfg .Host , sc .cfg .User , credType )
209
212
delete (localCredCache , target )
210
213
j , err := json .Marshal (localCredCache )
211
214
if err != nil {
212
- logger .Debugf ("failed to convert credential to JSON." )
215
+ logger .Warnf ("failed to convert credential to JSON." )
216
+ return
213
217
}
214
- temporaryCredCacheLock .Lock ()
215
218
writeTemporaryCacheFile (j )
216
- temporaryCredCacheLock .Unlock ()
217
219
}
218
220
}
219
221
0 commit comments