revel / revel

A high productivity, full-stack web framework for the Go language.

Home Page:http://revel.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pass pointer to variable to goroutine leads to nil values

goevexx opened this issue · comments

I have the following issue in the Revel framework:
In my revel app i use revel modules. In one module is a function

func addToBlocklist(r *revel.Request, claims map[string]interface{})

which is called by

go addToBlocklist(c.Request, c.Args[jwt.TokenClaimsKey].(map[string]interface{}))

c is of type

type JwtAuth struct {
	*revel.Controller
}

reve.Controller's Request is of type *revel.Request, just as expected by addToBlocklist.
When I fmt.Println(c.Request) before passing to addToBlocklist, it prints &{0xc0003079b0 0xc0003280b0 text/html html <nil> GET 127.0.0.1:35376 0.0.0.0:9001 /logout map[] <nil> 0xc0003265b0}
When I fmt.Println(r) in the first place of addToBlocklist it prints &{<nil> 0xc0003280b0 <nil> <nil> map[] <nil> 0xc0003265b0}

This runs on docker machine with golang:1.14.6-alpine.

When I run it locally on go 1.14.6 windows the values of r in addToBlocklist are just as they were passed.

I also opened a new thread on golangbridge, because this might not be revel-dependent. Pass pointer to variable to goroutine leads to nil values

Found out by adding defer fmt.Println(c) that the function, which is calling addToBlocklist, ends before addToBlocklist runs. And the Controller seems to be niled before addToBlocklist runs.

RefreshToken:  &{0xc00030b980 0xc000328080 text/html html   <nil> GET 127.0.0.1:35546 0.0.0.0:9001 /refresh-token map[] <nil> 0xc0002e4c30}
End RefreshToken:  &{0xc00030b980 0xc000328080 text/html html   <nil> GET 127.0.0.1:35546 0.0.0.0:9001 /refresh-token map[] <nil> 0xc0002e4c30}
addToBlockList:  &{<nil> 0xc000328080     <nil>    <nil> map[] <nil> 0xc0002e4c30}