fix race condition detected by go test -race