open-consul/sdk/freeport
Pierre Souchay fa1f9eb144
[BUGFIX] Fix race condition in freeport (#7567)
This removes a race condition in reset since pendingPorts can be set to nil in reset()

If ticker is hit at wrong time, it would crash the unit test.

We ensure in reset to avoid this race condition by cancelling the goroutine using
killTicker chan.

We also properly clean up eveything, so garbage collector can work as expected.

To reproduce existing bug:
`while go test -timeout 30s github.com/hashicorp/consul/sdk/freeport -run '^(Test.*)$'; do go clean -testcache; done`

Will crash after a few 10s runs on my machine.

Error could be seen in unit tests sometimes:

[INFO] freeport: resetting the freeport package state
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x1125536]

goroutine 25 [running]:
container/list.(*List).Len(...)
	/usr/local/Cellar/go/1.14/libexec/src/container/list/list.go:66
github.com/hashicorp/consul/sdk/freeport.checkFreedPortsOnce()
	/Users/p.souchay/go/src/github.com/hashicorp/consul/sdk/freeport/freeport.go:157 +0x86
github.com/hashicorp/consul/sdk/freeport.checkFreedPorts()
	/Users/p.souchay/go/src/github.com/hashicorp/consul/sdk/freeport/freeport.go:147 +0x71
created by github.com/hashicorp/consul/sdk/freeport.initialize
	/Users/p.souchay/go/src/github.com/hashicorp/consul/sdk/freeport/freeport.go:113 +0x2cf
FAIL	github.com/hashicorp/consul/sdk/freeport	1.607s
2020-04-01 13:14:33 -05:00
..
ephemeral_darwin.go Proper detection of ephemeral ports on Mac OS (#7539) 2020-03-30 09:13:03 -04:00
ephemeral_darwin_test.go Proper detection of ephemeral ports on Mac OS (#7539) 2020-03-30 09:13:03 -04:00
ephemeral_fallback.go Proper detection of ephemeral ports on Mac OS (#7539) 2020-03-30 09:13:03 -04:00
ephemeral_linux.go change sysctl call to use absolute path 2019-11-15 14:28:13 -08:00
ephemeral_linux_test.go sdk: add freelist tracking and ephemeral port range skipping to freeport 2019-09-17 14:30:43 -05:00
freeport.go [BUGFIX] Fix race condition in freeport (#7567) 2020-04-01 13:14:33 -05:00
freeport_test.go connect: check if intermediate cert needs to be renewed. (#6835) 2020-01-17 23:27:13 +01:00
systemlimit.go connect: check if intermediate cert needs to be renewed. (#6835) 2020-01-17 23:27:13 +01:00
systemlimit_windows.go connect: check if intermediate cert needs to be renewed. (#6835) 2020-01-17 23:27:13 +01:00