diff --git a/cloudstate/discovery/server.go b/cloudstate/discovery/server.go index 327c055..c776a5a 100644 --- a/cloudstate/discovery/server.go +++ b/cloudstate/discovery/server.go @@ -138,8 +138,9 @@ func (s *EntityDiscoveryServer) RegisterCRDTEntity(entity *crdt.Entity, config p return fmt.Errorf("failed to resolveFileDescriptor for DescriptorConfig: %+v: %w", config, err) } s.entitySpec.Entities = append(s.entitySpec.Entities, &protocol.Entity{ - EntityType: protocol.CRDT, - ServiceName: entity.ServiceName.String(), + EntityType: protocol.CRDT, + ServiceName: entity.ServiceName.String(), + PersistenceId: entity.ServiceName.String(), // make sure CRDT entities have unique keys per service }) return s.updateSpec() } diff --git a/cloudstate/eventsourced/context.go b/cloudstate/eventsourced/context.go index 11581b8..f41aabe 100644 --- a/cloudstate/eventsourced/context.go +++ b/cloudstate/eventsourced/context.go @@ -94,6 +94,13 @@ func (c *Context) fail(err error) { c.failed = err } +func (c *Context) reset() { + c.events = nil + c.failed = nil + c.forward = nil + c.sideEffects = nil +} + func (c *Context) resetSnapshotEvery() { c.shouldSnapshot = false } diff --git a/cloudstate/eventsourced/server.go b/cloudstate/eventsourced/server.go index c4eec13..3125212 100644 --- a/cloudstate/eventsourced/server.go +++ b/cloudstate/eventsourced/server.go @@ -128,6 +128,7 @@ func (s *Server) handle(stream entity.EventSourced_HandleServer) error { // see: https://github.com/cloudstateio/cloudstate/pull/119#discussion_r444851439 return fmt.Errorf("failed context was not reported: %w", r.context.failed) } + r.context.reset() msg, err := r.stream.Recv() switch err { case nil: