Skip to content

Commit bc19540

Browse files
authored
build: compile with golang 1.16 (#3803)
## Summary This PR upgrade the go-algorand repository to use go 1.16 while adding workarounds for golang/go#44343. ## Test Plan Use performance testing to verify no regressions.
1 parent 5a9f94a commit bc19540

File tree

19 files changed

+115
-29
lines changed

19 files changed

+115
-29
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ commands:
196196
shell: bash.exe
197197
command: |
198198
choco install -y msys2 pacman make wget --force
199-
choco install -y golang --version=1.14.7 --force
199+
choco install -y golang --version=1.16.11 --force
200200
choco install -y python3 --version=3.7.3 --force
201201
export msys2='cmd //C RefreshEnv.cmd '
202202
export msys2+='& set MSYS=winsymlinks:nativestrict '

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install golang
2121
uses: actions/setup-go@v2
2222
with:
23-
go-version: '1.14.7'
23+
go-version: '1.16.11'
2424
- name: Build Test
2525
run: |
2626
export ALGORAND_DEADLOCK=enable

.github/workflows/reviewdog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Install specific golang
4545
uses: actions/setup-go@v2
4646
with:
47-
go-version: '1.16.6'
47+
go-version: '1.16.11'
4848
- name: Create folders for golangci-lint
4949
run: mkdir -p cicdtmp/golangci-lint
5050
- name: Check if custom golangci-lint is already built

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ else
88
export GOPATH := $(shell go env GOPATH)
99
GOPATH1 := $(firstword $(subst :, ,$(GOPATH)))
1010
endif
11-
export GO111MODULE := on
1211
export GOPROXY := direct
1312
SRCPATH := $(shell pwd)
1413
ARCH := $(shell ./scripts/archtype.sh)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/algorand/go-algorand
22

3-
go 1.14
3+
go 1.16
44

55
require (
66
github.com/algorand/falcon v0.0.0-20220130164023-c9e1d466f123

network/dialer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/algorand/go-algorand/tools/network/dnssec"
25+
"github.com/algorand/go-algorand/util"
2526
)
2627

2728
type netDialer interface {
@@ -79,7 +80,7 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.
7980
select {
8081
case <-ctx.Done():
8182
return nil, ctx.Err()
82-
case <-time.After(waitTime):
83+
case <-util.NanoAfter(waitTime):
8384
}
8485
}
8586
conn, err := d.innerDialContext(ctx, network, address)

network/rateLimitingTransport.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"errors"
2121
"net/http"
2222
"time"
23+
24+
"github.com/algorand/go-algorand/util"
2325
)
2426

2527
// rateLimitingTransport is the transport for execute a single HTTP transaction, obtaining the Response for a given Request.
@@ -57,17 +59,18 @@ func makeRateLimitingTransport(phonebook Phonebook, queueingTimeout time.Duratio
5759
func (r *rateLimitingTransport) RoundTrip(req *http.Request) (res *http.Response, err error) {
5860
var waitTime time.Duration
5961
var provisionalTime time.Time
60-
queueingTimedOut := time.After(r.queueingTimeout)
62+
queueingDeadline := time.Now().Add(r.queueingTimeout)
6163
for {
6264
_, waitTime, provisionalTime = r.phonebook.GetConnectionWaitTime(req.Host)
6365
if waitTime == 0 {
6466
break // break out of the loop and proceed to the connection
6567
}
66-
select {
67-
case <-time.After(waitTime):
68-
case <-queueingTimedOut:
69-
return nil, ErrConnectionQueueingTimeout
68+
waitDeadline := time.Now().Add(waitTime)
69+
if waitDeadline.Before(queueingDeadline) {
70+
util.NanoSleep(waitTime)
71+
continue
7072
}
73+
return nil, ErrConnectionQueueingTimeout
7174
}
7275
res, err = r.innerTransport.RoundTrip(req)
7376
r.phonebook.UpdateConnectionTime(req.Host, provisionalTime)

network/wsNetwork.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
"github.com/algorand/go-algorand/protocol"
4949
tools_network "github.com/algorand/go-algorand/tools/network"
5050
"github.com/algorand/go-algorand/tools/network/dnssec"
51+
"github.com/algorand/go-algorand/util"
5152
"github.com/algorand/go-algorand/util/metrics"
5253
)
5354

@@ -1274,7 +1275,7 @@ func (wn *WebsocketNetwork) broadcastThread() {
12741275
}
12751276
}
12761277
select {
1277-
case <-time.After(sleepDuration):
1278+
case <-util.NanoAfter(sleepDuration):
12781279
if (request != nil) && time.Now().After(requestDeadline) {
12791280
// message time have elapsed.
12801281
return true

scripts/buildtools/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/algorand/go-algorand/scripts/buildtools
22

3-
go 1.14
3+
go 1.16
44

55
require (
66
github.com/algorand/msgp v1.1.49

scripts/buildtools/install_buildtools.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,14 @@ function install_go_module {
7070
# Check for version to go.mod version
7171
VERSION=$(get_go_version "$1")
7272

73-
# TODO: When we switch to 1.16 this should be changed to use 'go install'
74-
# instead of 'go get': https://tip.golang.org/doc/go1.16#modules
7573
if [ -z "$VERSION" ]; then
7674
echo "Unable to install requested package '$1' (${MODULE}): no version listed in ${SCRIPTPATH}/go.mod"
7775
exit 1
7876
else
79-
OUTPUT=$(GO111MODULE=on go get "${MODULE}@${VERSION}" 2>&1)
77+
OUTPUT=$(go install "${MODULE}@${VERSION}" 2>&1)
8078
fi
8179
if [ $? != 0 ]; then
82-
echo "error: executing \"go get ${MODULE}\" failed : ${OUTPUT}"
80+
echo "error: executing \"go install ${MODULE}\" failed : ${OUTPUT}"
8381
exit 1
8482
fi
8583
}

0 commit comments

Comments
 (0)