set deadline
Some checks failed
Build and Publish / BuildAndDeployAmd64 (push) Failing after 29s
Build and Publish / BuildAndDeploy (push) Successful in 2m13s

This commit is contained in:
matst80
2024-11-12 13:02:06 +01:00
parent edd4913ebd
commit b44b31307b
2 changed files with 5 additions and 2 deletions

View File

@@ -62,6 +62,7 @@ func (m *CartTCPClient) Connect() error {
func (m *CartTCPClient) SendPacket(messageType uint32, id CartId, data []byte) error { func (m *CartTCPClient) SendPacket(messageType uint32, id CartId, data []byte) error {
err := m.Connect() err := m.Connect()
if err != nil { if err != nil {
return err return err
} }
@@ -75,6 +76,7 @@ func (m *CartTCPClient) SendPacket(messageType uint32, id CartId, data []byte) e
return err return err
} }
_, err = m.Conn.Write(data) _, err = m.Conn.Write(data)
m.Conn.SetDeadline(time.Now().Add(time.Second * 10))
return err return err
} }
@@ -95,7 +97,7 @@ func (m *CartTCPClient) Call(messageType uint32, id CartId, responseType uint32,
select { select {
case ret := <-packetChan: case ret := <-packetChan:
return &ret, nil return &ret, nil
case <-time.After(time.Second): case <-time.After(time.Second * 10):
return nil, fmt.Errorf("timeout") return nil, fmt.Errorf("timeout")
} }
} }

View File

@@ -81,6 +81,7 @@ func (m *TCPClient) SendPacket(messageType uint32, data []byte) error {
return m.HandleConnectionError(err) return m.HandleConnectionError(err)
} }
_, err = m.Conn.Write(data) _, err = m.Conn.Write(data)
m.Conn.SetDeadline(time.Now().Add(time.Second * 10))
return m.HandleConnectionError(err) return m.HandleConnectionError(err)
} }
@@ -102,7 +103,7 @@ func (m *TCPClient) Call(messageType uint32, responseType uint32, data []byte) (
select { select {
case ret := <-packetChan: case ret := <-packetChan:
return &ret, nil return &ret, nil
case <-time.After(time.Second): case <-time.After(time.Second * 10):
return nil, fmt.Errorf("timeout") return nil, fmt.Errorf("timeout")
} }
} }