Skip to content

Add Unix domain socket support for Firebird 6 - #73

Open
Pavlushechko wants to merge 7 commits into
FirebirdSQL:mainfrom
Pavlushechko:codex/71-unix-socket
Open

Pavlushechko wants to merge 7 commits into
FirebirdSQL:mainfrom
Pavlushechko:codex/71-unix-socket

Conversation

@Pavlushechko

@Pavlushechko Pavlushechko commented Dec 1, 2026 •

Copy link
Copy Markdown

Fixes #71
Accepts a Unix domain socket path in host= for database connections and event notifications.
Verified on Firebird 6 in Ubuntu WSL and native Windows with TCP disabled. The integration test used a temporary version-parser fix and depends on #49.

Comment thread fbconn/events_channel.go Resolved
Comment thread fbconn/config.go Resolved
Comment thread conn_test.go Resolved
Comment thread conn_test.go Resolved
Comment thread conn_test.go Resolved
Comment thread fbconn/fbconn.go Resolved
Comment thread fbconn/fbconn_test.go
env string
}{
{"TCP", "FBX_TEST_DATABASE"},
{"Unix", "FBX_TEST_UNIX_SOCKET_DATABASE"},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add separate testcases for event manager and service manager connections

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added separate integration tests for both managers. The event test checks that a notification is delivered, and the service test runs TraceList. Both passed over Unix sockets with TCP disabled on Linux and Windows.

Comment thread fbconn/config.go
//
// # Keyword/Value
// user=sysdba password=masterkey host=localhost port=3050 database=employee.fdb
// user=sysdba password=masterkey host=/run/firebird/firebird.sock database=employee

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also support URI syntax when connecting with socket. Some pgx tests were cleaned up, but now can be restored or used as reference to check if we properly parse URI.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the original pgx cases. The existing parser already accepts firebird:///employee?host=/run/firebird/firebird.sock. I documented that form and added parsing tests for Linux and Windows paths, plus a percent-encoded path in the URI host.

@smirnoffjr
smirnoffjr requested a review from MrTeeett December 3, 2026 06:55
Comment thread .github/workflows/go.yml Outdated
echo Start RDB
if [ -e /etc/init.d/reddatabase ]; then
/etc/init.d/reddatabase start
/etc/init.d/reddatabase "$service_action"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Red Database is stopped after installation (Firebird started by default), there is no point to restart

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the restart. CI now configures the socket before starting Red Database, since the installer leaves it stopped.

Comment thread fbconn/events_channel.go

switch m := msg.(type) {
case *fbproto.OpResponse:
if isAbsolutePath(fbConn.eventHost) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After Hijack followed by Construct on a working Unix connection, the first QueueEvent calls DialFunc with tcp localhost:28016. Construct does not restore eventHost, so this branch reads the m and p bytes of /tmp/. as a TCP port.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hijack now saves the selected host, and Construct restores it. I added a regression test that queues an event after reconstructing a Unix connection.

Comment thread fbconn/events_channel.go
address := net.JoinHostPort(host, strconv.Itoa(auxPort))
auxConn, err := fbConn.config.DialFunc(ctx, "tcp", address)
network, address := NetworkAddress(host, port)
auxConn, err := fbConn.config.DialFunc(ctx, network, address)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once Firebird has returned the auxiliary address, it is waiting for the second connection. If FBX rejects the address or the dial fails here, QueueEvent returns an error but the next Ping on the same attachment reaches its deadline. This reproduced with a one-second timeout.

On protocols 13+, libfbclient sends op_abort_aux_connection on a failed auxiliary connect and marks the attachment broken. Could we cancel the pending accept on both error paths and test that the next operation completes promptly?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both paths now close the connection and send op_abort_aux_connection on protocol 13+. The tests verify that Ping returns a connection-closed error before its deadline. I also covered the case where Firebird rejects the request before returning an address. In that case, Ping still succeeds.

Comment thread fbconn/events_channel.go Outdated
if isAbsolutePath(fbConn.eventHost) {
// Firebird sends the auxiliary socket path as raw bytes for Unix connections.
path := string(m.Data)
if !isAbsolutePath(path) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With RemoteServiceUnixSocket = sockets/fb.sock, Firebird 6 returns sockets/fb_event.<pid>.<n> even when the client opened the main socket using an absolute path. Both libfbclient and Jaybird Native delivered the event when the client’s working directory resolved that path. FBX rejects the reply here before calling DialFunc.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FBX now passes the relative path returned by Firebird to DialFunc with the unix network. I added a regression test and verified event delivery on Firebird 6 in WSL with a relative socket path and TCP disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support of Unix Domain Sockets (Firebird 6)

4 participants