Skip to content

Commit b962f3d

Browse files
author
Dean Karn
committed
Correct Var tagCache locking
1 parent 230db62 commit b962f3d

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package validator
22
================
33
<img align="right" src="https://raw.githubusercontent.com/go-playground/validator/v9/logo.png">[![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4-
![Project status](https://img.shields.io/badge/version-9.9.2-green.svg)
4+
![Project status](https://img.shields.io/badge/version-9.9.3-green.svg)
55
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/validator/branches/v9/badge.svg)](https://semaphoreci.com/joeybloggs/validator)
66
[![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=v9&service=github)](https://coveralls.io/github/go-playground/validator?branch=v9)
77
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator)

validator.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,7 @@ OUTER:
473473
)
474474

475475
return
476-
477476
}
478-
479477
ct = ct.next
480478
}
481479
}

validator_instance.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ func (v *Validate) VarCtx(ctx context.Context, field interface{}, tag string) (e
524524
ctag, ok := v.tagCache.Get(tag)
525525
if !ok {
526526
v.tagCache.lock.Lock()
527-
defer v.tagCache.lock.Unlock()
528527

529528
// could have been multiple trying to access, but once first is done this ensures tag
530529
// isn't parsed again.
@@ -533,14 +532,14 @@ func (v *Validate) VarCtx(ctx context.Context, field interface{}, tag string) (e
533532
ctag, _ = v.parseFieldTagsRecursive(tag, "", "", false)
534533
v.tagCache.Set(tag, ctag)
535534
}
535+
v.tagCache.lock.Unlock()
536536
}
537537

538538
val := reflect.ValueOf(field)
539539

540540
vd := v.pool.Get().(*validate)
541541
vd.top = val
542542
vd.isPartial = false
543-
544543
vd.traverseField(ctx, val, val, vd.ns[0:0], vd.actualNs[0:0], defaultCField, ctag)
545544

546545
if len(vd.errs) > 0 {
@@ -595,7 +594,6 @@ func (v *Validate) VarWithValueCtx(ctx context.Context, field interface{}, other
595594
ctag, ok := v.tagCache.Get(tag)
596595
if !ok {
597596
v.tagCache.lock.Lock()
598-
defer v.tagCache.lock.Unlock()
599597

600598
// could have been multiple trying to access, but once first is done this ensures tag
601599
// isn't parsed again.
@@ -604,6 +602,7 @@ func (v *Validate) VarWithValueCtx(ctx context.Context, field interface{}, other
604602
ctag, _ = v.parseFieldTagsRecursive(tag, "", "", false)
605603
v.tagCache.Set(tag, ctag)
606604
}
605+
v.tagCache.lock.Unlock()
607606
}
608607

609608
otherVal := reflect.ValueOf(other)

0 commit comments

Comments
 (0)