Commit 129cb53
committed
[yugabyte#30747] docdb: Fix nullptr crash in ThreadCategoryTracker::RegisterMetricEntity
Summary:
**Issue:**
we observed following error:
```
thread #1, name = 'yb-tserver', stop reason = signal SIGSEGV
MetricPrototype::entity_type
MetricEntity::CheckInstantiation
MetricEntity::FindOrCreateMetric<FunctionGauge<...>>
GaugePrototype::InstantiateFunctionGauge
ThreadCategoryTracker::RegisterMetricEntity
ThreadMgr::StartInstrumentation
StartThreadInstrumentation
RpcAndWebServerBase::RpcAndWebServerBase
CQLServer::CQLServer
TabletServerMain
```
`CheckInstantiation` was called with a null metric prototype, i.e. something in `entries_` had gauge_proto is nullptr.
The cause is, scrape-time `GetCategory` acess `entries_` without any lock, so it could run while we were still registering that metric category. That lines up with the sequence below:
1. `RegisterGaugeForAllMetricEntities` wires `GetCategory` into the function gauges, callback is live(but `entries_` is not updated at this point)
2. A metrics scrape runs that callback `GetCategory`. `entries_[category].metric` insert a default row since category not exist yet (gauge proto null).
3. `RegisterMetricEntity` walks `entries_` and does `entry.gauge_proto->...` This hits the stub SIGSEGV.
**Fix: **
wire FunctionGauge to only check the atomic value so scrapes only load the atomic, not entries_. That also removes concurrent std::map no lock access
Test Plan: Jenkins
Reviewers: sergei
Reviewed By: sergei
Subscribers: ybase, hsunder
Differential Revision: https://phorge.dev.yugabyte.com/D513751 parent daba5a9 commit 129cb53
1 file changed
Lines changed: 18 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
183 | 188 | | |
184 | 189 | | |
185 | 190 | | |
| |||
189 | 194 | | |
190 | 195 | | |
191 | 196 | | |
192 | | - | |
193 | | - | |
| 197 | + | |
194 | 198 | | |
195 | 199 | | |
196 | 200 | | |
197 | | - | |
| 201 | + | |
198 | 202 | | |
199 | 203 | | |
200 | 204 | | |
| |||
205 | 209 | | |
206 | 210 | | |
207 | 211 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
| 222 | + | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | | - | |
| 226 | + | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
| 233 | + | |
232 | 234 | | |
233 | 235 | | |
234 | 236 | | |
| |||
238 | 240 | | |
239 | 241 | | |
240 | 242 | | |
241 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
242 | 246 | | |
243 | 247 | | |
244 | 248 | | |
245 | | - | |
| 249 | + | |
246 | 250 | | |
247 | 251 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
| 252 | + | |
252 | 253 | | |
253 | 254 | | |
254 | 255 | | |
| |||
0 commit comments