fix
This commit is contained in:
parent
e2b174a58f
commit
22ee293bfb
|
@ -93,6 +93,7 @@ type userConnPoolCtlChanItem struct {
|
||||||
// 每个连接的连接基本属性
|
// 每个连接的连接基本属性
|
||||||
type wsConnectItem struct {
|
type wsConnectItem struct {
|
||||||
conn *websocket.Conn //websocket的连接(基本属性)
|
conn *websocket.Conn //websocket的连接(基本属性)
|
||||||
|
connExpireTime int64 //websocket过期时间(跟随连接时候的token过期时间)
|
||||||
userAgent string //用户代理头信息(基本属性,用于重连标识验证因素之一)
|
userAgent string //用户代理头信息(基本属性,用于重连标识验证因素之一)
|
||||||
logic *DataTransferLogic //logic(基本属性,用于获取上下文,配置或者操作数据库)
|
logic *DataTransferLogic //logic(基本属性,用于获取上下文,配置或者操作数据库)
|
||||||
closeChan chan struct{} //ws连接关闭chan(基本属性)
|
closeChan chan struct{} //ws连接关闭chan(基本属性)
|
||||||
|
@ -213,19 +214,25 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
||||||
uniqueId = oldWid
|
uniqueId = oldWid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//默认过期时间
|
||||||
|
connExpireTime := time.Now().UTC().Add(time.Second * time.Duration(l.svcCtx.Config.Auth.AccessExpire)).Unix()
|
||||||
|
if userInfo.Exp > 0 {
|
||||||
|
connExpireTime = userInfo.Exp
|
||||||
|
}
|
||||||
renderCtx, renderCtxCancelFunc := context.WithCancel(l.ctx)
|
renderCtx, renderCtxCancelFunc := context.WithCancel(l.ctx)
|
||||||
ws := wsConnectItem{
|
ws := wsConnectItem{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
userAgent: userAgent,
|
connExpireTime: connExpireTime,
|
||||||
logic: l,
|
userAgent: userAgent,
|
||||||
closeChan: make(chan struct{}, 1),
|
logic: l,
|
||||||
isClose: false,
|
closeChan: make(chan struct{}, 1),
|
||||||
uniqueId: uniqueId,
|
isClose: false,
|
||||||
inChan: make(chan []byte, websocketInChanLen),
|
uniqueId: uniqueId,
|
||||||
outChan: make(chan []byte, websocketOutChanLen),
|
inChan: make(chan []byte, websocketInChanLen),
|
||||||
mutex: sync.Mutex{},
|
outChan: make(chan []byte, websocketOutChanLen),
|
||||||
userId: userInfo.UserId,
|
mutex: sync.Mutex{},
|
||||||
guestId: userInfo.GuestId,
|
userId: userInfo.UserId,
|
||||||
|
guestId: userInfo.GuestId,
|
||||||
extendRenderProperty: extendRenderProperty{
|
extendRenderProperty: extendRenderProperty{
|
||||||
renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen),
|
renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen),
|
||||||
renderCtx: renderCtx,
|
renderCtx: renderCtx,
|
||||||
|
@ -327,6 +334,12 @@ func (w *wsConnectItem) heartbeat() {
|
||||||
case <-w.closeChan:
|
case <-w.closeChan:
|
||||||
return
|
return
|
||||||
case <-tick:
|
case <-tick:
|
||||||
|
//看看token是否过期了
|
||||||
|
if w.connExpireTime > 0 && w.connExpireTime < time.Now().UTC().Unix() {
|
||||||
|
logx.Info("token过期,关闭连接:", w.uniqueId)
|
||||||
|
w.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
//发送心跳信息
|
//发送心跳信息
|
||||||
if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil {
|
if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil {
|
||||||
logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err)
|
logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user