porsager / porsager/postgres

Unix sockets support on windows

Open
#737 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

Thanks for the library! Had an issue with what probably is an edge-case, using unix sockets on windows.

UNIX sockets are supported by postgresql on windows (I can start and connect to a database with psql without listenening on any IP), but i cannot connect with postgres.js.

If I try something like

const sql = postgres({
  path: postgresqlServer.socketDir,
  user: 'surface',
  password: 'surface'
 })
 console.log(await sql`SELECT NOW()`)

I get

  Error: connect EPERM C:\Users\surface\Downloads\db\socket
      at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
      at cachedError (file:///C:/Users/surface/Downloads/node_modules/postgres/src/query.js:170:23)
      at new Query (file:///C:/Users/surface/Downloads/node_modules/postgres/src/query.js:36:24)
      at sql (file:///C:/Users/surface/Downloads/node_modules/postgres/src/index.js:112:11)
      at TestContext.<anonymous> (file:///C:/Users/surface/Downloads/tests/test-run.test.js:17:23) {
    errno: -4048,
    code: 'EPERM',
    syscall: 'connect',
    address: 'C:\\Users\\surface\\Downloads\\db\\socket'

But if I try with an actual psql.exe it works:

psql.exe -d 'postgres://surface:surface@surface/postgres?host=C:\Users\surface\Downloads\db\socket'

Had a similar issue with node-postgres so opened a issue there too: https://github.com/brianc/node-postgres/issues/3100

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/test-run.test.js and trace the connection path through src/index.js and src/query.js, then reproduce the Windows UNIX-socket case from the issue. Done means the shown postgres.js example connects to the PostgreSQL socket and completes SELECT NOW() without the EPERM error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.