Commit e5aa423
committed
fix: suppress net.ErrClosed on concurrent Close
Close and CloseNow returned a wrapped net.ErrClosed when the
internal read loop or write path won the casClosing race before
the user-facing call. The defer that suppresses net.ErrClosed
was only registered on the CAS winner path.
Separate user-facing close tracking from internal close
coordination. A userClosed atomic tracks whether the user has
called Close/CloseNow before. Combined with isClosed, this
gives three distinct behaviors:
- First user call, close in progress or peer closed: nil.
- Concurrent user calls while close is in progress: nil,
returns instantly without blocking.
- User call after close has fully completed: net.ErrClosed.1 parent d099e16 commit e5aa423
2 files changed
Lines changed: 14 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 102 | + | |
107 | 103 | | |
108 | 104 | | |
109 | 105 | | |
| |||
112 | 108 | | |
113 | 109 | | |
114 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 135 | + | |
140 | 136 | | |
141 | 137 | | |
142 | 138 | | |
| |||
145 | 141 | | |
146 | 142 | | |
147 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
82 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
0 commit comments