Commit 6db064c
committed
gbn: serialize interval-aware ticker resets
Protect IntervalAwareForceTicker lifecycle operations with a mutex so
Reset, ResetWithInterval, Stop, and ForceTick cannot replace or stop the
underlying time.Ticker concurrently.
The keepalive timeout compatibility tests exercise concurrent send and
receive paths that both reset the ping/pong tickers. In normal
operation, sendPacketsForever can reset the pong ticker when starting a
keepalive ping while receivePacketsForever resets the ping ticker when a
packet arrives. The interval-aware ticker implementation mutated its
ticker, quit channel, and interval fields without synchronization, so
the race detector could observe concurrent reads and writes in the reset
path.
This change adds a dedicated lock around ticker lifecycle updates and
uses a locked helper for interval resets. That preserves the existing
behavior while making the ticker safe under the concurrent reset pattern
used by the keepalive logic.
Why the fix was needed:
The new keepalive compatibility tests made two
goroutines hit the ticker harder:
- sendPacketsForever() resets the pong ticker when it sends a keepalive
ping.
- receivePacketsForever() resets the ping ticker when packets arrive.
IntervalAwareForceTicker internally stops and recreates its time.Ticker,
replaces quit, and updates interval.
Before the fix, those fields were changed without a mutex, so
overlapping resets could race. go test -race caught exactly that in
ticker.go:143-162.
So the fix was needed because:
- the ticker was not safe under concurrent reset/stop operations
- the keepalive code legitimately does concurrent resets
- race CI was correctly flagging unsynchronized internal state mutation
The mutex makes those lifecycle operations atomic and keeps the
implementation behavior the same.1 parent 47db8cb commit 6db064c
1 file changed
Lines changed: 31 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
129 | 133 | | |
130 | 134 | | |
131 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
132 | 139 | | |
133 | 140 | | |
134 | 141 | | |
| |||
138 | 145 | | |
139 | 146 | | |
140 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
141 | 159 | | |
142 | 160 | | |
143 | 161 | | |
| |||
159 | 177 | | |
160 | 178 | | |
161 | 179 | | |
162 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
163 | 184 | | |
164 | 185 | | |
165 | 186 | | |
166 | 187 | | |
167 | 188 | | |
168 | 189 | | |
169 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
170 | 194 | | |
171 | 195 | | |
172 | 196 | | |
| |||
183 | 207 | | |
184 | 208 | | |
185 | 209 | | |
186 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
187 | 215 | | |
188 | 216 | | |
189 | 217 | | |
| |||
0 commit comments