Skip to content

Commit

Permalink
connect: add fix for long socket paths
Browse files Browse the repository at this point in the history
Now relative path is used instead of real for console socket.
It is used to prevent console socket path from being too long.

Closes #124
  • Loading branch information
better0fdead authored and LeonidVas committed Nov 17, 2022
1 parent 17f7428 commit d1a955a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cli/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package connector
import (
"fmt"
"net"
"os"
"path/filepath"
"runtime"
"time"

"github.com/tarantool/go-tarantool"
)

const (
greetingOperationTimeout = 3 * time.Second
maxSocketPathLinux = 108
maxSocketPathMac = 106
)

// RequestOpts describes the parameters of a request to be executed.
Expand Down Expand Up @@ -37,6 +42,29 @@ type Connector interface {

// Connect connects to the tarantool instance according to options.
func Connect(opts ConnectOpts) (Connector, error) {
// It became common that address is longer than 108 symbols(sun_path limit).
// To reduce length of address we use relative path
// with chdir into a directory of socket.
// e.g foo/bar/123.sock -> ./123.sock
workDir, err := os.Getwd()
if err != nil {
return nil, err
}

maxSocketPath := maxSocketPathLinux
if runtime.GOOS == "darwin" {
maxSocketPath = maxSocketPathMac
}

if _, err := os.Stat(opts.Address); err == nil {
os.Chdir(filepath.Dir(opts.Address))
opts.Address = "./" + filepath.Base(opts.Address)
if len(opts.Address)+1 > maxSocketPath {
return nil, fmt.Errorf("socket name is longer than %d symbols: %s",
maxSocketPath-3, filepath.Base(opts.Address))
}
defer os.Chdir(workDir)
}
// Connect to specified address.
greetingConn, err := net.Dial(opts.Network, opts.Address)
if err != nil {
Expand Down

0 comments on commit d1a955a

Please sign in to comment.