From 76f6495903932853b3e2c18463577a6a8b25c4b6 Mon Sep 17 00:00:00 2001 From: Jonathan Vuillemin Date: Tue, 9 Jul 2024 09:19:08 +0200 Subject: [PATCH 1/2] feat(fxgcppubsub): Fixed race conditions on avro binary codec --- fxgcppubsub/codec/avro.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fxgcppubsub/codec/avro.go b/fxgcppubsub/codec/avro.go index d6a5259..4b01189 100644 --- a/fxgcppubsub/codec/avro.go +++ b/fxgcppubsub/codec/avro.go @@ -15,15 +15,18 @@ var ( // AvroBinaryCodec is a Codec implementation for encoding and decoding with avro schema in binary format. type AvroBinaryCodec struct { + cache *avro.SchemaCache api avro.API schema avro.Schema } // NewAvroBinaryCodec returns a new AvroBinaryCodec instance. func NewAvroBinaryCodec(schemaDefinition string) (*AvroBinaryCodec, error) { + cache := &avro.SchemaCache{} + api := avro.Config{}.Freeze() - schema, err := avro.Parse(schemaDefinition) + schema, err := avro.ParseBytesWithCache([]byte(schemaDefinition), "", cache) if err != nil { return nil, fmt.Errorf("cannot parse avro schema: %w", err) } From 9cf0a9e6fd81539cdb75806c330c663a2b67bf04 Mon Sep 17 00:00:00 2001 From: Jonathan Vuillemin Date: Tue, 9 Jul 2024 09:27:08 +0200 Subject: [PATCH 2/2] feat(fxgcppubsub): Fixed race conditions on avro binary codec --- fxgcppubsub/codec/avro.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fxgcppubsub/codec/avro.go b/fxgcppubsub/codec/avro.go index 4b01189..3330686 100644 --- a/fxgcppubsub/codec/avro.go +++ b/fxgcppubsub/codec/avro.go @@ -15,18 +15,15 @@ var ( // AvroBinaryCodec is a Codec implementation for encoding and decoding with avro schema in binary format. type AvroBinaryCodec struct { - cache *avro.SchemaCache api avro.API schema avro.Schema } // NewAvroBinaryCodec returns a new AvroBinaryCodec instance. func NewAvroBinaryCodec(schemaDefinition string) (*AvroBinaryCodec, error) { - cache := &avro.SchemaCache{} - api := avro.Config{}.Freeze() - schema, err := avro.ParseBytesWithCache([]byte(schemaDefinition), "", cache) + schema, err := avro.ParseBytesWithCache([]byte(schemaDefinition), "", &avro.SchemaCache{}) if err != nil { return nil, fmt.Errorf("cannot parse avro schema: %w", err) }