Fasthttp: Coarse time causes race condition to time.Local change

Created on 16 Jun 2017  路  3Comments  路  Source: valyala/fasthttp

https://github.com/valyala/fasthttp/blob/master/coarseTime.go#L22

    t := time.Now().Truncate(time.Second)

When this line runs in a goroutine it reads time.Local with time.Now(). Because goroutine starts from init() external application has a very limited control over public and exported time.Local.

This simple code would trigger race condition

func main() {
    time.Local = time.UTC
        // continue app initialization
}

Most helpful comment

It is not clear why @valyala introduced this coarse time. Benchmarks on
different systems show that the speedup is no where enough to justify
the added code complexity.

See: https://github.com/erikdubbelboer/fasthttp/commit/033e10c58522144bd570ff3aa45fbd2f3df917db (this is a fork I maintain until @valyala starts maintaining this project again)

All 3 comments

It is not clear why @valyala introduced this coarse time. Benchmarks on
different systems show that the speedup is no where enough to justify
the added code complexity.

See: https://github.com/erikdubbelboer/fasthttp/commit/033e10c58522144bd570ff3aa45fbd2f3df917db (this is a fork I maintain until @valyala starts maintaining this project again)

fixed, but useful note: do not change time.Location. This variable should be the system's timezone, not your service's one. you should probably change system timezone instead of overwriting global variables.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kirillDanshin picture kirillDanshin  路  5Comments

LeMoussel picture LeMoussel  路  3Comments

imgurbot12 picture imgurbot12  路  5Comments

mayocream picture mayocream  路  3Comments

horgh picture horgh  路  5Comments