|
@@ -7,6 +7,7 @@ import (
|
|
|
"sparrow/pkg/models"
|
|
|
"sparrow/pkg/rpcs"
|
|
|
"sparrow/pkg/server"
|
|
|
+ "sync"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -37,6 +38,7 @@ type Connection struct {
|
|
|
VendorId string
|
|
|
closeChan chan struct{}
|
|
|
DeviceCode string
|
|
|
+ mLock sync.Mutex
|
|
|
}
|
|
|
|
|
|
// NewConnection create a connection
|
|
@@ -120,6 +122,8 @@ func (c *Connection) ValidateToken(token []byte) error {
|
|
|
|
|
|
// Close close
|
|
|
func (c *Connection) Close() {
|
|
|
+ c.mLock.Lock()
|
|
|
+ defer c.mLock.Unlock()
|
|
|
DeviceID := c.DeviceID
|
|
|
server.Log.Infof("closing connection of device %v", DeviceID)
|
|
|
if c.Conn != nil {
|