Skip to content

Commit 47721e2

Browse files
authored
Merge pull request #35 from button-chen/v1
fix: If SetWriteDeadline is set, set it back later
2 parents 1584211 + 9376ad2 commit 47721e2

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

connection.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,20 @@ func (c *Conn) SendCommand(ctx context.Context, cmd command.Command) (*RawRespon
135135
c.writeLock.Unlock()
136136
}
137137

138-
if deadline, ok := ctx.Deadline(); ok {
139-
c.writeLock.Lock()
138+
deadline, ok := ctx.Deadline()
139+
c.writeLock.Lock()
140+
if ok {
140141
_ = c.conn.SetWriteDeadline(deadline)
141-
c.writeLock.Unlock()
142142
}
143-
144-
c.writeLock.Lock()
145143
_, err := c.conn.Write([]byte(cmd.BuildMessage() + EndOfMessage))
146-
c.writeLock.Unlock()
147144
if err != nil {
145+
c.writeLock.Unlock()
148146
return nil, err
149147
}
148+
if ok {
149+
_ = c.conn.SetWriteDeadline(time.Time{})
150+
}
151+
c.writeLock.Unlock()
150152

151153
// Get response
152154
c.responseChanMutex.RLock()

0 commit comments

Comments
 (0)