From bd59b3c1d75e53df73ef9a733205d251c081a87d Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Fri, 16 Apr 2021 12:13:51 +0800 Subject: [PATCH] other: improve login Signed-off-by: Jianhui Zhao --- broker.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/broker.go b/broker.go index 411b5ac..326d419 100644 --- a/broker.go +++ b/broker.go @@ -1,8 +1,9 @@ package main import ( - "encoding/binary" "crypto/x509" + "encoding/binary" + "time" "github.com/gorilla/websocket" jsoniter "github.com/json-iterator/go" @@ -83,8 +84,10 @@ func (br *broker) run() { } else { if dev, ok := br.devices[devid]; ok { if _, ok := br.waitLoginUsers[devid]; ok { - userLoginAck(loginErrorBusy, c) - log.Error().Msg("login fail, device busy") + log.Error().Msg("Another user is logining the device, wait...") + time.AfterFunc(time.Millisecond*10, func() { + br.register <- c + }) } else { br.waitLoginUsers[devid] = c dev.WriteMsg(msgTypeLogin, []byte{})