Skip to content

Commit

Permalink
fix(node): outgoing event dispatch lock
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Apr 8, 2019
1 parent 94aa178 commit 10eeeac
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 5 additions & 1 deletion core/entity/conversation.go
Expand Up @@ -511,7 +511,11 @@ func (m *conversationMember) Write(at time.Time, message *Message) error {
if m.conversation.IsOneToOne() {
m.conversation.Infos = message.Text
} else {
m.conversation.Infos = m.Contact.DisplayName + ": " + message.Text
if m.Contact != nil {
m.conversation.Infos = m.Contact.DisplayName + ": " + message.Text
} else {
m.conversation.Infos = "Anonymous" + ": " + message.Text
}
}

return nil
Expand Down
1 change: 0 additions & 1 deletion core/node/event.go
Expand Up @@ -40,7 +40,6 @@ func (n *Node) handleEvent(ctx context.Context, input *entity.Event) error {
ctx = tracer.Context()

defer n.asyncWaitGroup(ctx)()
defer n.handleMutex(ctx)()

if input.SourceDeviceID == n.UserID() {
logger().Debug("skipping event created by myself",
Expand Down
8 changes: 5 additions & 3 deletions core/node/p2pclient.go
Expand Up @@ -67,9 +67,11 @@ func (n *Node) EnqueueOutgoingEventWithOptions(ctx context.Context, event *entit
return errors.New("no active dispatches for a freshly added outgoing event")
}

for _, dispatch := range dispatches {
n.outgoingEvents <- dispatch
}
go func() {
for _, dispatch := range dispatches {
n.outgoingEvents <- dispatch
}
}()

tracer.SetMetadata("new-outgoing-event", event.ID)

Expand Down
16 changes: 15 additions & 1 deletion core/node/sql.go
Expand Up @@ -123,13 +123,27 @@ func (n *Node) createCommitLog(scope *gorm.Scope, operation string, reflectValue
case *entity.Config:
log.Entity = &node.CommitLog_Entity{Config: data}
case *entity.Event:
if operation != "delete" {
data, err = sql.EventByID(scope.DB(), data.ID)
if err != nil {
return nil
}
}
log.Entity = &node.CommitLog_Entity{Event: data}
case *entity.DevicePushConfig:
log.Entity = &node.CommitLog_Entity{DevicePushConfig: data}
case *entity.DevicePushIdentifier:
log.Entity = &node.CommitLog_Entity{DevicePushIdentifier: data}
case *entity.EventDispatch:
log.Entity = &node.CommitLog_Entity{EventDispatch: data}
var event *entity.Event
if operation != "delete" {
event, err = sql.EventByID(scope.DB(), data.EventID)
if err != nil {
return nil
}
log.Entity = &node.CommitLog_Entity{Event: event}
}
// log.Entity = &node.CommitLog_Entity{EventDispatch: data}
case *entity.SenderAlias:
log.Entity = &node.CommitLog_Entity{SenderAlias: data}
default:
Expand Down

0 comments on commit 10eeeac

Please sign in to comment.