New() creates a race condition if called with -race

Open
#70 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
go
Domain
backend

Research direction

Start at requestid.New and trace the global variable writes mentioned in the issue. Run the relevant tests with Go's -race flag, then verify that concurrent calls no longer report a race and that the request ID middleware can use distinct header keys for separate servers as described.

Written by the indexing model from the issue text.

Description

If executing multiple calls to requestid.New (in tests for example) the writing to a global var produces a race condition, this can easily be avoided with a simple lock supplementing the global var.

This kinda raised another question for me, what if I want to use the request id middleware for multiple servers in a single app with different header keys?

I honestly think it would best to save the header key in the gin context for that request and later if fetched check in the context what the key is.

Dominant language
Go
Stars
262
Forks
20
Avg merge
3d 3h
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.