From 611ffdf5a8b1f658d29dcfd93e92028ee15a02a3 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 24 Apr 2023 11:10:40 +0100 Subject: 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! --- guix-build-coordinator/coordinator.scm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'guix-build-coordinator/coordinator.scm') 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 () -- cgit v1.2.3