File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff 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.
220226func (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 )
You can’t perform that action at this time.
0 commit comments