Skip to content

Commit

Permalink
Turn 'already running' error into info
Browse files Browse the repository at this point in the history
  • Loading branch information
alebeck committed Nov 16, 2024
1 parent b6e5a21 commit 0a0cbee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion cmd/boring/tunnels.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"path/filepath"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -126,7 +127,12 @@ func openTunnel(t *tunnel.Tunnel) {
}

if !resp.Success {
log.Errorf("Tunnel '%v' could not be opened: %v", t.Name, resp.Error)
// cannot use errors.Is because error is transmitted as string over IPC
if strings.HasSuffix(resp.Error, daemon.AlreadyRunning.Error()) {
log.Infof("Tunnel '%v' is already running.", t.Name)
return
}
log.Errorf("Could not open tunnel '%v': %v", t.Name, resp.Error)
} else {
log.Infof("Opened tunnel '%s': %s %v %s via %s.", log.Green+log.Bold+t.Name+log.Reset,
t.LocalAddress, t.Mode, t.RemoteAddress, t.Host)
Expand Down
4 changes: 3 additions & 1 deletion internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/alebeck/boring/internal/tunnel"
)

var AlreadyRunning = errors.New("already running")

type state struct {
// TODO: write proper concurrent map structure for this
tunnels map[string]*tunnel.Tunnel
Expand Down Expand Up @@ -148,7 +150,7 @@ func openTunnel(s *state, conn net.Conn, t tunnel.Tunnel) {
_, exists := s.tunnels[t.Name]
s.mutex.RUnlock()
if exists {
err = fmt.Errorf("already running")
err = AlreadyRunning
log.Errorf("%v: could not open: %v", t.Name, err)
return
}
Expand Down

0 comments on commit 0a0cbee

Please sign in to comment.