Skip to content

Commit

Permalink
Fix setting up connection to non-IP sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
sylwiaszunejko committed Jun 11, 2024
1 parent 6ef4d7f commit cdcabe3
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
6 changes: 5 additions & 1 deletion control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
71 changes: 71 additions & 0 deletions control_integration_test.go
Original file line number Diff line number Diff line change
@@ -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:", 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)
}
}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit cdcabe3

Please sign in to comment.