浏览代码

Move post-connection ping to after chat list times out

Tulir Asokan 4 年之前
父节点
当前提交
7c67fe75eb
共有 1 个文件被更改,包括 15 次插入8 次删除
  1. 15 8
      user.go

+ 15 - 8
user.go

@@ -455,17 +455,13 @@ func (user *User) sendMarkdownBridgeAlert(formatString string, args ...interface
 	}
 }
 
-func (user *User) intPostLogin() {
-	defer user.syncWait.Done()
-	user.createCommunity()
-	user.tryAutomaticDoublePuppeting()
-
+func (user *User) postConnPing() bool {
 	err := user.Conn.AdminTest()
 	if err != nil {
 		user.log.Errorfln("Post-connection ping failed: %v. Disconnecting and then reconnecting after a second", err)
 		sess, disconnectErr := user.Conn.Disconnect()
 		if disconnectErr != nil {
-			user.log.Warnln("Error while disconnecting after failed post-login ping:", disconnectErr)
+			user.log.Warnln("Error while disconnecting after failed post-connection ping:", disconnectErr)
 		} else {
 			user.Session = &sess
 		}
@@ -474,16 +470,27 @@ func (user *User) intPostLogin() {
 			time.Sleep(1 * time.Second)
 			user.tryReconnect(fmt.Sprintf("Post-connection ping failed: %v", err))
 		}()
-		return
+		return false
 	} else {
-		user.log.Debugln("Post-login ping OK")
+		user.log.Debugln("Post-connection ping OK")
+		return true
 	}
+}
+
+func (user *User) intPostLogin() {
+	defer user.syncWait.Done()
+	user.createCommunity()
+	user.tryAutomaticDoublePuppeting()
 
 	select {
 	case <-user.chatListReceived:
 		user.log.Debugln("Chat list receive confirmation received in PostLogin")
 	case <-time.After(time.Duration(user.bridge.Config.Bridge.ChatListWait) * time.Second):
 		user.log.Warnln("Timed out waiting for chat list to arrive!")
+		user.postConnPing()
+		return
+	}
+	if !user.postConnPing() {
 		return
 	}
 	select {