diff --git a/control.go b/control.go index 3806f45a3..5a21baf26 100644 --- a/control.go +++ b/control.go @@ -270,7 +270,11 @@ type connHost struct { func (c *controlConn) setupConn(conn *Conn) error { // we need up-to-date host info for the filterHost call below iter := conn.querySystemLocal(context.TODO()) - host, err := c.session.hostInfoFromIter(iter, conn.host.connectAddress, conn.conn.RemoteAddr().(*net.TCPAddr).Port) + defaultPort := 9042 + if tcpAddr, ok := conn.conn.RemoteAddr().(*net.TCPAddr); ok { + defaultPort = tcpAddr.Port + } + host, err := c.session.hostInfoFromIter(iter, conn.host.connectAddress, defaultPort) if err != nil { return err } diff --git a/control_integration_test.go b/control_integration_test.go new file mode 100644 index 000000000..1705730e7 --- /dev/null +++ b/control_integration_test.go @@ -0,0 +1,71 @@ +//go:build integration && scylla +// +build integration,scylla + +package gocql + +import ( + "context" + "fmt" + "net" + "testing" +) + +// unixSocketDialer is a special dialer which connects only to the maintenance_socket. +type unixSocketDialer struct { + dialer net.Dialer + socketPath string +} + +func (d unixSocketDialer) DialContext(_ context.Context, _, _ string) (net.Conn, error) { + return d.dialer.Dial("unix", d.socketPath) +} + +func TestUnixSockets(t *testing.T) { + socketPath := "/tmp/scylla/cql.m" + + c := createCluster() + c.NumConns = 1 + c.DisableInitialHostLookup = true + c.ProtoVersion = 3 + c.ReconnectInterval = 0 + c.WriteCoalesceWaitTime = 0 + + c.Events.DisableNodeStatusEvents = true + c.Events.DisableTopologyEvents = true + c.Events.DisableSchemaEvents = true + + d := net.Dialer{ + Timeout: c.Timeout, + } + if c.SocketKeepalive > 0 { + d.KeepAlive = c.SocketKeepalive + } + + c.Dialer = unixSocketDialer{ + dialer: d, + socketPath: socketPath, + } + + sess, err := c.CreateSession() + if err != nil { + panic(fmt.Sprintf("unable to create session: %v", err)) + } + + defer sess.Close() + + keyspace := "test1" + + err = createTable(sess, `DROP KEYSPACE IF EXISTS `+keyspace) + if err != nil { + t.Fatal("unable to drop keyspace if exists:", err) + } + + err = createTable(sess, fmt.Sprintf(`CREATE KEYSPACE %s + WITH replication = { + 'class' : 'SimpleStrategy', + 'replication_factor' : 1 + }`, keyspace)) + if err != nil { + t.Fatal("unable to create keyspace:", err) + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 77ad6b8b8..5a8ef974c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,7 @@ services: public: ipv4_address: 192.168.100.11 volumes: + - /tmp/scylla:/var/lib/scylla/ - type: bind source: ./testdata/config/scylla.yaml target: /etc/scylla/scylla.yaml diff --git a/integration.sh b/integration.sh index 51f6eeb04..07d67f64b 100755 --- a/integration.sh +++ b/integration.sh @@ -27,6 +27,8 @@ function scylla_restart() { scylla_restart +sudo chmod 0777 /tmp/scylla/cql.m + readonly clusterSize=1 readonly multiNodeClusterSize=3 readonly scylla_liveset="192.168.100.11" diff --git a/testdata/config/scylla.yaml b/testdata/config/scylla.yaml index 68ee54a9e..676d513cc 100644 --- a/testdata/config/scylla.yaml +++ b/testdata/config/scylla.yaml @@ -8,3 +8,4 @@ client_encryption_options: keyfile: /etc/scylla/db.key truststore: /etc/scylla/ca.crt require_client_auth: true +maintenance_socket: workdir