Skip to content

Commit

Permalink
Close broken connections (#71)
Browse files Browse the repository at this point in the history
Close broken connections
  • Loading branch information
andig authored Dec 1, 2024
1 parent 17dea2c commit fb6e8bc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rscp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ func (c *Client) send(messages []Message) error {
return err
}
if err := c.conn.SetWriteDeadline(time.Now().Add(c.config.SendTimeout)); err != nil {
_ = c.Disconnect()
return err
}
if _, err := c.conn.Write(msg); err != nil {
_ = c.Disconnect()
return err
}
return nil
Expand All @@ -68,6 +70,7 @@ func (c *Client) send(messages []Message) error {
// receive listens for a response and decodes the response
func (c *Client) receive() ([]Message, error) {
if err := c.conn.SetReadDeadline(time.Now().Add(c.config.ReceiveTimeout)); err != nil {
_ = c.Disconnect()
return nil, err
}

Expand All @@ -81,7 +84,8 @@ func (c *Client) receive() ([]Message, error) {
var err error

if i, err = c.conn.Read(data); err != nil {
return nil, fmt.Errorf("error during receive response: %w", err)
_ = c.Disconnect()
return nil, err
} else if i == 0 {
return nil, ErrRscpInvalidFrameLength
}
Expand Down

0 comments on commit fb6e8bc

Please sign in to comment.