Skip to content

Commit d45fcdf

Browse files
authored
fix: remove cache for thrift reflection to avoid race (#229)
1 parent c700587 commit d45fcdf

File tree

2 files changed

+9
-61
lines changed

2 files changed

+9
-61
lines changed

thrift_reflection/descriptor-extend.go

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ func (s *ServiceDescriptor) GetParent() *ServiceDescriptor {
259259
}
260260

261261
func (s *ServiceDescriptor) GetAllMethods() []*MethodDescriptor {
262-
263262
allMethods := []*MethodDescriptor{}
264263

265264
svc := s
@@ -271,7 +270,6 @@ func (s *ServiceDescriptor) GetAllMethods() []*MethodDescriptor {
271270
}
272271

273272
func (s *ServiceDescriptor) GetMethodByNameFromAll(name string) *MethodDescriptor {
274-
275273
for _, m := range s.GetAllMethods() {
276274
if m.GetName() == name {
277275
return m
@@ -338,67 +336,27 @@ func (td *TypeDescriptor) GetStructDescriptor() (*StructDescriptor, error) {
338336
}
339337

340338
func (td *TypeDescriptor) IsException() bool {
341-
if td.Extra == nil {
342-
td.Extra = map[string]string{}
343-
}
344-
cacheType, ok := td.Extra["type"]
345-
if ok {
346-
return cacheType == "exception"
347-
}
348339
sd, err := td.GetExceptionDescriptor()
349-
isStruct := err == nil && sd != nil
350-
if isStruct {
351-
td.Extra["type"] = "exception"
352-
}
353-
return isStruct
340+
isException := err == nil && sd != nil
341+
return isException
354342
}
355343

356344
func (td *TypeDescriptor) IsUnion() bool {
357-
if td.Extra == nil {
358-
td.Extra = map[string]string{}
359-
}
360-
cacheType, ok := td.Extra["type"]
361-
if ok {
362-
return cacheType == "union"
363-
}
364345
sd, err := td.GetUnionDescriptor()
365-
isStruct := err == nil && sd != nil
366-
if isStruct {
367-
td.Extra["type"] = "union"
368-
}
369-
return isStruct
346+
isUnion := err == nil && sd != nil
347+
return isUnion
370348
}
371349

372350
func (td *TypeDescriptor) IsStruct() bool {
373-
if td.Extra == nil {
374-
td.Extra = map[string]string{}
375-
}
376-
cacheType, ok := td.Extra["type"]
377-
if ok {
378-
return cacheType == "struct"
379-
}
380351
sd, err := td.GetStructDescriptor()
381352
isStruct := err == nil && sd != nil
382-
if isStruct {
383-
td.Extra["type"] = "struct"
384-
}
385353
return isStruct
386354
}
387355

388356
func (td *TypeDescriptor) IsEnum() bool {
389-
if td.Extra == nil {
390-
td.Extra = map[string]string{}
391-
}
392-
cacheType, ok := td.Extra["type"]
393-
if ok {
394-
return cacheType == "enum"
395-
}
396357
sd, err := td.GetEnumDescriptor()
397-
isStruct := err == nil && sd != nil
398-
if isStruct {
399-
td.Extra["type"] = "enum"
400-
}
401-
return isStruct
358+
isEnum := err == nil && sd != nil
359+
return isEnum
402360
}
403361

404362
func (td *TypeDescriptor) GetEnumDescriptor() (*EnumDescriptor, error) {
@@ -417,19 +375,9 @@ func (td *TypeDescriptor) GetEnumDescriptor() (*EnumDescriptor, error) {
417375
}
418376

419377
func (td *TypeDescriptor) IsTypedef() bool {
420-
if td.Extra == nil {
421-
td.Extra = map[string]string{}
422-
}
423-
cacheType, ok := td.Extra["type"]
424-
if ok {
425-
return cacheType == "typedef"
426-
}
427378
sd, err := td.GetTypedefDescriptor()
428-
isStruct := err == nil && sd != nil
429-
if isStruct {
430-
td.Extra["type"] = "typedef"
431-
}
432-
return isStruct
379+
isTypedef := err == nil && sd != nil
380+
return isTypedef
433381
}
434382

435383
func (td *TypeDescriptor) GetTypedefDescriptor() (*TypedefDescriptor, error) {

version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
package version
1616

17-
const ThriftgoVersion = "0.3.16"
17+
const ThriftgoVersion = "0.3.17"

0 commit comments

Comments
 (0)