Commit b7e401f
committed
Partially handled race conditions when reading the signature
Since the "signature" SST field is not actually monotonic (a later
signature won't validate as an earlier signature), and signatures don't
contain their version numbers, there is actually a race condition
between a remote node updating "signature" and "signed_num" while the
local node is trying to do handle_verify_request. Since the remote node
writes in the order (1) signature (2) signed_num, while the local node
reads in the order (1) signed_num (2) signature, the local node could
read an earlier signed_num and then a later signature. This causes
signature validation to fail because the local node retrieves the wrong
signature from its log to compare (e.g. it retrieves signature 15, when
the signature it got from the SST is the signature for version 17).
This race condition can be mostly fixed by having the local node re-read
the signed_num after reading the signature and compare it with the value
it has cached. If signed_num changed while reading the signature, it
means the read interleaved with the remote node's write and we need to
try again. If signed_num has the same value twice, it's probably the
correct value (matches the signature). It is still slightly possible
to get an inconsistent read if the remote node overwrites the signature
exactly as the local node is reading it (so it won't have changed
signed_num when the local node reads it a second time), but the window
for that race condition is much smaller.1 parent 94094dd commit b7e401f
2 files changed
Lines changed: 22 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
235 | | - | |
236 | | - | |
| 234 | + | |
| 235 | + | |
237 | 236 | | |
238 | 237 | | |
239 | 238 | | |
| |||
245 | 244 | | |
246 | 245 | | |
247 | 246 | | |
248 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
249 | 250 | | |
250 | | - | |
251 | | - | |
252 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
253 | 266 | | |
254 | 267 | | |
255 | 268 | | |
| |||
0 commit comments