Up to Main Index Up to Journal for October, 2021 JOURNAL FOR SATURDAY 9TH OCTOBER, 2021 ______________________________________________________________________________ SUBJECT: Fix for data race on experiment branch DATE: Sat 9 Oct 20:25:36 BST 2021 I’ve just pushed out a quick minor update to the experiment branch that fixes a data race when events are triggered. Back in August I made a one-line change to core.Thing.Schedule to clean up the event timers when an event fires: commit a421285f13cb48941aa685025ba6d9c5e3d612c8 Author: Andrew 'Diddymus' Rolfe <diddymus@wolfmud.org> Date: Sun Aug 8 19:23:14 2021 +0100 core: Thing.Schedule cancel event when it fires to clean up state Signed-off-by: Andrew 'Diddymus' Rolfe <diddymus@wolfmud.org> diff --git a/core/thing.go b/core/thing.go index 95d3e03..61bea58 100644 --- a/core/thing.go +++ b/core/thing.go @@ -522,6 +522,7 @@ func (t *Thing) Schedule(event eventKey) { t.Int[idx+DueAtOffset] = time.Now().Add(wait).UnixNano() t.Event[event] = time.AfterFunc( wait, func() { + t.Cancel(event) NewState(t).Parse(eventCommands[event]) }, ) However, Cancel is called on a separate goroutine by time.AfterFunc calling an anonymous function. This means Cancel is called without the state.BWL (Big World Lock) being held causing a data race. This has now been fixed by moving the call to Cancel into the individual event handlers. I managed to trigger the data race when running the race detector to check some changes I’ve been making to re-introduce the front-end for account login and character creation. I love the race detector and find it invaluable when developing. Especially when working on WolfMUD which uses a lot of goroutines. Unfortunately, I don’t run with the race detector as much as I should. The simple reason being that it can very quickly eat gigabytes of memory. My desktop only has 8Gb RAM. Running with only 128 bots can use over 1Gb RAM :( I’ve included two other minor fixes in the update. The world loader now correctly accepts ‘Veto’ and ‘Vetoes’ as field names in zone files. Before it only accepted ‘Veto’. The other update changes ‘Reference’ to ‘Ref’ in core.asNames to match the field in zone and player files. At the moment it is only used in the output of the #DUMP command. -- Diddymus Up to Main Index Up to Journal for October, 2021