Prevents panic using freed slice in pool#2000
Conversation
…king Error() calls which reference underlying labels Signed-off-by: Owen Diehl <ow.diehl@gmail.com>
|
I find it hard to see how this particular change makes the program entirely safe; please file an issue detailing the panics so that we can understand more about what went wrong. |
pracucci
left a comment
There was a problem hiding this comment.
I haven't seen the stack trace yet, but looking at the change history I suspect the regression has been introduced in the PR #1922.
Before the PR #1922, the metric labels were stringified at the error creation time; after the change, a reference to the labels is kept within the error and stringified when the WrappedError() is call, which occurs after the client.ReuseSlice() is called. In this scenario, the change introduced in this PR fixes it.
I agree with @bboreham that would be better add a comment to explain it. Would be also interesting to see if we can cover this regression with a unit test: does a test concurrently calling Push() and run with -race spot it?
|
We should also note the change in behaviour here: previously requests were not re-used if they caused a hard error (i.e. an error that is not simply validation). This was discussed in #1863 (which is almost exactly the same PR). |
…king Error() calls which reference underlying labels (cortexproject#2000) Signed-off-by: Owen Diehl <ow.diehl@gmail.com>
|
Here is the full panic. This was an Grafana Labs' release from (internal) r70 branch, commit bc6996bf, based on master 1a3b008 + some PRs: #1749, #1878, #1935, #1960. Here is link to the line 317 in ingester.go: |
|
Do we know the path through |
Actually I think it does. It's not the |
|
Hold on. I think my previous message is incorrect. The labels are stored in the This stuff is tricky tho. |
That seems sufficiently difficult to prove I'm going to change the code so we don't have to. |
This defers putting a slice back into the pool (ingester push path) to prevent panicking Error() calls which reference the underlying labels.
This defers returning an allocated slice to its pool until after use. Previously we saw panics on
Error()calls which held references to the underlying timeseries label set.