Fix bug if portal sync finishes early

This commit is contained in:
Tulir Asokan 2021-02-10 20:59:50 +02:00
parent 87ead90e03
commit e6045a3cf5

View file

@ -176,8 +176,8 @@ func (bridge *Bridge) NewUser(dbUser *database.User) *User {
IsRelaybot: false, IsRelaybot: false,
chatListReceived: make(chan struct{}), chatListReceived: make(chan struct{}, 1),
syncPortalsDone: make(chan struct{}), syncPortalsDone: make(chan struct{}, 1),
syncStart: make(chan struct{}, 1), syncStart: make(chan struct{}, 1),
messageInput: make(chan PortalMessage), messageInput: make(chan PortalMessage),
messageOutput: make(chan PortalMessage, bridge.Config.Bridge.UserMessageBuffer), messageOutput: make(chan PortalMessage, bridge.Config.Bridge.UserMessageBuffer),
@ -453,8 +453,8 @@ func (user *User) PostLogin() {
user.log.Debugln("Locking processing of incoming messages and starting post-login sync") user.log.Debugln("Locking processing of incoming messages and starting post-login sync")
// TODO can an old sync still be ongoing when PostLogin is called again? // TODO can an old sync still be ongoing when PostLogin is called again?
// TODO 2: can the new sync happen before this happens? // TODO 2: can the new sync happen before this happens?
user.chatListReceived = make(chan struct{}) user.chatListReceived = make(chan struct{}, 1)
user.syncPortalsDone = make(chan struct{}) user.syncPortalsDone = make(chan struct{}, 1)
user.syncWait.Add(1) user.syncWait.Add(1)
user.syncStart <- struct{}{} user.syncStart <- struct{}{}
go user.intPostLogin(user.Conn) go user.intPostLogin(user.Conn)