Commit 280b4ed
authored
Fix minor
## Summary of changes
Fixes two minor bugs, discovered while refactoring
## Reason for change
Spotted the bugs while refactoring other things. They are unlikely to
hit in production, but are worth fixing, and orthogonal to the rest of
the refactoring
## Implementation details
- `MessagePackSerializer.Serialize` writes to a _shared_ buffer. Given
that the cache could well be used inside a _different_ call to
`MessagePackSerializer.Serialize`, that could end up corrupting the
cache. Instead, get the string bytes directly, which creates a new
write-sized array instead.
- The `_forceFlush` field is accessed from different threads, and is
replaced from both. Need Volatile/Interlocked to ensure that you don't
get a stale reference
## Test coverage
Meh, I considered a test for the MessagePackStringCache.cs issue, but
it's pretty niche, and would only be re-introduced if you change the
code back, so figured the comment was sufficient.
## Other details
Part of a stackAgentWriter bugs (#9013)1 parent 34f116e commit 280b4ed
2 files changed
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
292 | | - | |
| 292 | + | |
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
310 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
154 | | - | |
| 153 | + | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
0 commit comments