Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix negative waitgroup #1372

Merged
merged 3 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,24 @@ host-apps-static: ## Build app
${STATIC_OPTS} go build -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' -o ./apps/ ./cmd/apps/vpn-server
${STATIC_OPTS} go build -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' -o ./apps/ ./cmd/apps/vpn-client

host-apps-deploy: ## Build app
test -d apps && rm -r apps || true
mkdir -p ./apps
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o ./apps/ ./cmd/apps/skychat
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o ./apps/ ./cmd/apps/skysocks
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o ./apps/ ./cmd/apps/skysocks-client
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o ./apps/ ./cmd/apps/vpn-server
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o ./apps/ ./cmd/apps/vpn-client

host-apps-race: ## Build app
test -d apps && rm -r apps || true
mkdir -p ./apps
CGO_ENABLED=1${OPTS} go build ${BUILD_OPTS} -race -o ./apps/ ./cmd/apps/skychat
CGO_ENABLED=1${OPTS} go build ${BUILD_OPTS} -race -o ./apps/ ./cmd/apps/skysocks
CGO_ENABLED=1${OPTS} go build ${BUILD_OPTS} -race -o ./apps/ ./cmd/apps/skysocks-client
CGO_ENABLED=1${OPTS} go build ${BUILD_OPTS} -race -o ./apps/ ./cmd/apps/vpn-server
CGO_ENABLED=1${OPTS} go build ${BUILD_OPTS} -race -o ./apps/ ./cmd/apps/vpn-client

# Bin
bin: ## Build `skywire-visor`, `skywire-cli`
${OPTS} go build ${BUILD_OPTS} -o ./ ./cmd/skywire-visor
Expand Down Expand Up @@ -270,12 +288,13 @@ bin-static: ## Build `skywire-visor`, `skywire-cli`
${STATIC_OPTS} go build -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' -o ./skywire-cli ./cmd/skywire-cli
${STATIC_OPTS} go build -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' -o ./setup-node ./cmd/setup-node

build-deploy: ## Build for deployment Docker images
build-deploy: host-apps-deploy ## Build for deployment Docker images
${OPTS} go build -tags netgo ${BUILD_OPTS_DEPLOY} -o /release/skywire-visor ./cmd/skywire-visor
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o /release/skywire-cli ./cmd/skywire-cli
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o /release/apps/skychat ./cmd/apps/skychat
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o /release/apps/skysocks ./cmd/apps/skysocks
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o /release/apps/skysocks-client ./cmd/apps/skysocks-client

build-race: host-apps-race ## Build for testing Docker images
CGO_ENABLED=1 ${OPTS} go build -tags netgo ${BUILD_OPTS} -race -o /release/skywire-visor ./cmd/skywire-visor
CGO_ENABLED=1 ${OPTS} go build ${BUILD_OPTS} -race -o /release/skywire-cli ./cmd/skywire-cli

github-prepare-release:
$(eval GITHUB_TAG=$(shell git describe --abbrev=0 --tags | cut -c 2-6))
Expand Down
6 changes: 3 additions & 3 deletions cmd/skywire-cli/commands/visor/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ var setAppSecureCmd = &cobra.Command{

var setAppPasscodeCmd = &cobra.Command{
Use: "passcode <name> <passcode>",
Short: "Set app passcode.\n\"remove\" is a special arg to remove the passcode",
Short: "Set app passcode.\n \"remove\" is a special arg to remove the passcode",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
passcode := args[1]
Expand All @@ -182,7 +182,7 @@ var setAppPasscodeCmd = &cobra.Command{

var setAppNetworkInterfaceCmd = &cobra.Command{
Use: "netifc <name> <interface>",
Short: "Set app network interface.\n\"remove\" is a special arg to remove the netifc",
Short: "Set app network interface.\n \"remove\" is a special arg to remove the netifc",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
netifc := args[1]
Expand All @@ -196,7 +196,7 @@ var setAppNetworkInterfaceCmd = &cobra.Command{

var appLogsSinceCmd = &cobra.Command{
Use: "log <name> <timestamp>",
Short: "Logs from app since RFC3339Nano-formatted timestamp.\n\"beginning\" is a special timestamp to fetch all the logs",
Short: "Logs from app since RFC3339Nano-formatted timestamp.\n \"beginning\" is a special timestamp to fetch all the logs",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
var t time.Time
Expand Down
1 change: 0 additions & 1 deletion docker/images/visor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ WORKDIR /skywire

RUN apk add --no-cache make git && \
sh -c /skywire/docker/images/visor/install-preq.sh && \
make host-apps && \
make build-deploy && \
mkdir -p /apps && \
cp ./apps/vpn-server /apps/ && \
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/appserver/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ type Proc struct {

cmdStderr io.ReadCloser

startWg sync.WaitGroup
readyCh chan struct{} // push here when ready to start app disc - protected by 'readyOnce'
readyOnce sync.Once // ensures we only push to 'readyCh' once
}

// NewProc constructs `Proc`.
Expand Down Expand Up @@ -104,14 +105,13 @@ func NewProc(mLog *logging.MasterLogger, conf appcommon.ProcConfig, disc appdisc
connCh: make(chan struct{}, 1),
m: m,
appName: appName,
startWg: sync.WaitGroup{},
readyCh: make(chan struct{}, 1),
cmdStderr: stderr,
}

if runtime.GOOS == "windows" {
p.ipcServerWg.Add(1)
}
p.startWg.Add(1)
return p
}

Expand Down Expand Up @@ -236,7 +236,7 @@ func (p *Proc) Start() error {

go func() {
// App discovery start/stop.
p.startWg.Wait()
<-p.readyCh
p.disc.Start()
}()
defer p.disc.Stop()
Expand Down Expand Up @@ -334,7 +334,7 @@ func (p *Proc) SetDetailedStatus(status string) {
p.statusMx.Lock()
defer p.statusMx.Unlock()
if status == AppDetailedStatusRunning {
p.startWg.Done()
p.readyOnce.Do(func() { close(p.readyCh) })
}

if status == AppDetailedStatusRunning || status == AppDetailedStatusStopped {
Expand Down