Browse Source

Fix bug if portal sync finishes early

Tulir Asokan 4 years ago
parent
commit
e6045a3cf5
1 changed files with 4 additions and 4 deletions
  1. 4 4
      user.go

+ 4 - 4
user.go

@@ -176,8 +176,8 @@ func (bridge *Bridge) NewUser(dbUser *database.User) *User {
 
 
 		IsRelaybot: false,
 		IsRelaybot: false,
 
 
-		chatListReceived: make(chan struct{}),
-		syncPortalsDone:  make(chan struct{}),
+		chatListReceived: make(chan struct{}, 1),
+		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.syncPortalsDone = make(chan struct{})
+	user.chatListReceived = make(chan struct{}, 1)
+	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)