jeroenrinzema / psql-wire

PostgreSQL server wire protocol. Build your own server and start serving connections.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query not received when querying via pgx

kishaningithub opened this issue · comments

I am using the latest version v0.3.0 of this, when i try to connect to a proxy with this test case the query never gets received

Test code using pgx connection

t.Run("test query execution", func(t *testing.T) {
	var name string
	var weight int64
	err = conn.QueryRow(context.Background(), "select name, weight from widgets limit 1").Scan(&name, &weight)
	require.NoError(t, err)
	fmt.Println(name, weight)
})

Debug logs

{"level":"debug","timestamp":"2022-10-19T18:42:12.915693+05:30","caller":"psql-wire@v0.3.0/command.go:61","msg":"incoming command","length":58,"type":"P"}
{"level":"debug","timestamp":"2022-10-19T18:42:12.915705+05:30","caller":"psql-wire@v0.3.0/command.go:61","msg":"incoming command","length":16,"type":"D"}
{"level":"debug","timestamp":"2022-10-19T18:42:12.915711+05:30","caller":"psql-wire@v0.3.0/command.go:61","msg":"incoming command","length":4,"type":"S"}
{"level":"debug","timestamp":"2022-10-19T18:42:12.915755+05:30","caller":"psql-wire@v0.3.0/command.go:61","msg":"incoming command","length":22,"type":"B"}
{"level":"debug","timestamp":"2022-10-19T18:42:12.915763+05:30","caller":"psql-wire@v0.3.0/command.go:61","msg":"incoming command","length":6,"type":"D"}
{"level":"debug","timestamp":"2022-10-19T18:42:12.915768+05:30","caller":"psql-wire@v0.3.0/command.go:61","msg":"incoming command","length":9,"type":"E"}
{"level":"debug","timestamp":"2022-10-19T18:42:12.915775+05:30","caller":"psql-wire@v0.3.0/command.go:61","msg":"incoming command","length":4,"type":"S"}

The full test code can be found here in my rdapp repo where i am trying to use this in order to create a postgres proxy for AWS redshift data API

Hi @kishaningithub, it looks like this query is using the extended query protocol. This issue will be resolved once #16 has been merged. Apologies for the inconvenience!

Let me know if i can help in anyway

@kishaningithub I have just released the latest version v0.4.0 including support for the extended query protocol. Would you be able to checkout the latest version and see if this resolves your issue?

Closing this issue for now. Feel free to open it again if the issue persists.

Sorry for my delayed update. v0.4.0 works beautifully. For the above test following is what i received in the debug logs

{"level":"info","timestamp":"2022-10-25T18:47:51.496612+05:30","caller":"psql-wire@v0.4.0/wire.go:88","msg":"serving incoming connections","addr":"127.0.0.1:25432"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.501158+05:30","caller":"psql-wire@v0.4.0/wire.go:126","msg":"serving a new client connection"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.501754+05:30","caller":"psql-wire@v0.4.0/handshake.go:137","msg":"attempting to upgrade the client to a TLS connection"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.501786+05:30","caller":"psql-wire@v0.4.0/handshake.go:140","msg":"no TLS certificates available continuing with a insecure connection"}
{"level":"error","timestamp":"2022-10-25T18:47:51.501945+05:30","caller":"psql-wire@v0.4.0/wire.go:116","msg":"an unexpected error got returned while serving a client connection","error":"EOF","stacktrace":"github.com/jeroenrinzema/psql-wire.(*Server).Serve.func2\n\t/Users/kishanb/go/pkg/mod/github.com/jeroenrinzema/psql-wire@v0.4.0/wire.go:116"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.502177+05:30","caller":"psql-wire@v0.4.0/wire.go:126","msg":"serving a new client connection"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.502311+05:30","caller":"psql-wire@v0.4.0/wire.go:137","msg":"handshake successfull, validating authentication"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.50233+05:30","caller":"psql-wire@v0.4.0/handshake.go:68","msg":"reading client parameters"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.502334+05:30","caller":"psql-wire@v0.4.0/handshake.go:86","msg":"client parameter","key":"user","value":"postgres"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.502338+05:30","caller":"psql-wire@v0.4.0/handshake.go:86","msg":"client parameter","key":"database","value":"postgres"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.502401+05:30","caller":"psql-wire@v0.4.0/auth.go:33","msg":"authenticating client connection"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.502474+05:30","caller":"psql-wire@v0.4.0/wire.go:150","msg":"connection authenticated, writing server parameters"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.50248+05:30","caller":"psql-wire@v0.4.0/handshake.go:102","msg":"writing server parameters"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.502484+05:30","caller":"psql-wire@v0.4.0/handshake.go:113","msg":"server parameter","key":"server_encoding","value":"UTF8"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.50249+05:30","caller":"psql-wire@v0.4.0/handshake.go:113","msg":"server parameter","key":"client_encoding","value":"UTF8"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.502495+05:30","caller":"psql-wire@v0.4.0/handshake.go:113","msg":"server parameter","key":"is_superuser","value":"off"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.502498+05:30","caller":"psql-wire@v0.4.0/handshake.go:113","msg":"server parameter","key":"session_authorization","value":"postgres"}
{"level":"debug","timestamp":"2022-10-25T18:47:51.502503+05:30","caller":"psql-wire@v0.4.0/command.go:39","msg":"ready for query... starting to consume commands"}