Commit 50c5fb1
BUG/MEDIUM: runtime: fix data race on lastError causing nil pointer panic
The lastError field was read by Listen() and written by the internal
listen() goroutine without synchronization. When Close() was called
externally (e.g. during HAProxy reload), the events channel could be
closed before listen() had set lastError. The caller would then read
a partially-written error interface value: a non-nil interface with a
nil underlying *wrapError pointer. Calling errors.Is() on this would
dereference the nil pointer in fmt.(*wrapError).Unwrap().
Fix by protecting lastError with a sync.Mutex via setLastError/
getLastError accessors. Also return io.EOF as a fallback when the
events channel is closed but no error was recorded, instead of
returning nil which callers would interpret as success.1 parent 52d98dd commit 50c5fb1
1 file changed
+27
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| |||
115 | 118 | | |
116 | 119 | | |
117 | 120 | | |
118 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
126 | 144 | | |
127 | 145 | | |
128 | 146 | | |
| |||
147 | 165 | | |
148 | 166 | | |
149 | 167 | | |
150 | | - | |
| 168 | + | |
151 | 169 | | |
152 | 170 | | |
153 | 171 | | |
154 | 172 | | |
155 | 173 | | |
156 | 174 | | |
157 | 175 | | |
158 | | - | |
| 176 | + | |
159 | 177 | | |
160 | 178 | | |
161 | 179 | | |
162 | 180 | | |
163 | 181 | | |
164 | 182 | | |
165 | | - | |
| 183 | + | |
166 | 184 | | |
167 | 185 | | |
168 | 186 | | |
| |||
0 commit comments