diff options
author | Christopher Baines <mail@cbaines.net> | 2023-04-24 11:10:40 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-04-24 11:10:40 +0100 |
commit | 611ffdf5a8b1f658d29dcfd93e92028ee15a02a3 (patch) | |
tree | 49ede13f123badffe2557bc4d292aebf7c510d07 /guix-build-coordinator | |
parent | dcc7569dbf519d27a2c38496eb934c5a2cb59db4 (diff) | |
download | build-coordinator-611ffdf5a8b1f658d29dcfd93e92028ee15a02a3.tar build-coordinator-611ffdf5a8b1f658d29dcfd93e92028ee15a02a3.tar.gz |
Reverse the atomic-box-set! and vector-set! when storing events
Updating the current state id and index before writing the new entry to the
vector is risky, since a thread could read the old entry if the timing is
unlucky.
Instead, write to the buffer first, then updating the current state id and
index. This will cause problems for listeners reading from the very end of the
buffer, but this can be a problem anyway if they're very behind, and they
already handle that circumstance.
Thanks to Ludo for reporting this!
Diffstat (limited to 'guix-build-coordinator')
-rw-r--r-- | guix-build-coordinator/coordinator.scm | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/guix-build-coordinator/coordinator.scm b/guix-build-coordinator/coordinator.scm index b3865e0..02bca86 100644 --- a/guix-build-coordinator/coordinator.scm +++ b/guix-build-coordinator/coordinator.scm @@ -220,13 +220,13 @@ (+ 1 event-buffer-index) buffer-size))) - (atomic-box-set! current-state-id-and-event-buffer-index-box - (cons new-state-id - new-event-index)) - (vector-set! event-buffer new-event-index - (list new-state-id event-name data)))))) + (list new-state-id event-name data)) + + (atomic-box-set! current-state-id-and-event-buffer-index-box + (cons new-state-id + new-event-index)))))) (spawn-fiber (lambda () |