Skip to content

Commit 930432f

Browse files
committed
comment prepareRead and readMu unlocking
1 parent e410eab commit 930432f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

read.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ func (c *Conn) readLoop(ctx context.Context) (header, error) {
217217
}
218218
}
219219

220+
// prepareRead sets the readTimeout context and returns a done function
221+
// to be called after the read is done. It also returns an error if the
222+
// connection is closed. The reference to the error is used to assign
223+
// an error depending on if the connection closed or the context timed
224+
// out during use. Typically the referenced error is a named return
225+
// variable of the function calling this method.
220226
func (c *Conn) prepareRead(ctx context.Context, err *error) (func(), error) {
221227
select {
222228
case <-c.closed:
@@ -335,6 +341,9 @@ func (c *Conn) handleControl(ctx context.Context, h header) (err error) {
335341
closeSent := c.closeSentErr != nil
336342
c.closeStateMu.Unlock()
337343

344+
// Only unlock readMu if this connection is being closed becaue
345+
// c.close will try to acquire the readMu lock. We unlock for
346+
// writeClose as well because it may also call c.close.
338347
if !closeSent {
339348
c.readMu.unlock()
340349
_ = c.writeClose(ce.Code, ce.Reason)

0 commit comments

Comments
 (0)