scalapb / zio-grpc

ScalaPB meets ZIO: write purely functional gRPC services and clients using ZIO
Apache License 2.0
257 stars 81 forks source link

Suspend the creation of Metadata in make with pairs #614

Closed ghostdogpr closed 3 months ago

ghostdogpr commented 3 months ago

The variant of SafeMetadata.make that takes pairs creates the Metadata object eagerly outside of the effect. That means that the same Metadata object will be used everytime we create SafeMetadata. That leads to catastrophic behavior as that object is not supposed to be shared and reused (java.lang.NullPointerException: Cannot invoke "io.grpc.Metadata$LazyValue.toBytes()" because "value" is null or Uncaught exception in the SynchronizationContext. Panic! in Netty).

This PR makes the creation of Metadata lazy.

thesamet commented 3 months ago

Wow - good catch!