Skip to content

Commit

Permalink
Merge pull request #35 from button-chen/v1
Browse files Browse the repository at this point in the history
fix: If SetWriteDeadline is set, set it back later
  • Loading branch information
mkravos authored Sep 20, 2024
2 parents 1584211 + 9376ad2 commit 47721e2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,20 @@ func (c *Conn) SendCommand(ctx context.Context, cmd command.Command) (*RawRespon
c.writeLock.Unlock()
}

if deadline, ok := ctx.Deadline(); ok {
c.writeLock.Lock()
deadline, ok := ctx.Deadline()
c.writeLock.Lock()
if ok {
_ = c.conn.SetWriteDeadline(deadline)
c.writeLock.Unlock()
}

c.writeLock.Lock()
_, err := c.conn.Write([]byte(cmd.BuildMessage() + EndOfMessage))
c.writeLock.Unlock()
if err != nil {
c.writeLock.Unlock()
return nil, err
}
if ok {
_ = c.conn.SetWriteDeadline(time.Time{})
}
c.writeLock.Unlock()

// Get response
c.responseChanMutex.RLock()
Expand Down

0 comments on commit 47721e2

Please sign in to comment.