Skip to content

Erroneous Go race detection #359

@ofek-frame

Description

@ofek-frame

Describe the bug

Currently, running parallel tests using this package with race detection on causes false positives of data races:

WARNING: DATA RACE
Read at 0x000005260ee8 by goroutine 11:
github.com/microsoftgraph/msgraph-sdk-go-core.getInstance()
/home/runner/go/pkg/mod/github.com/microsoftgraph/[email protected]/error_mappings_registry.go:19 +0x30
github.com/microsoftgraph/msgraph-sdk-go-core.GetErrorFactoryFromRegistry()
/home/runner/go/pkg/mod/github.com/microsoftgraph/[email protected]/error_mappings_registry.go:55 +0x2b

...

Previous write at 0x000005260ee8 by goroutine 34:
github.com/microsoftgraph/msgraph-sdk-go-core.getInstance()
/home/runner/go/pkg/mod/github.com/microsoftgraph/[email protected]/error_mappings_registry.go:23 +0x12f
github.com/microsoftgraph/msgraph-sdk-go-core.GetErrorFactoryFromRegistry()
/home/runner/go/pkg/mod/github.com/microsoftgraph/[email protected]/error_mappings_registry.go:55 +0x2b

The issue seems to be in:

if singleInstance == nil {

The optimistic nil check triggers a read-write race detection - perhaps it can be disabled when go test -race is on?

Expected behavior

Go's race detection won't fail tests when using the package in it

How to reproduce

Run tests using the package in parallel with -race specified in go test's arguments.

SDK Version

No response

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions