porsager / porsager/postgres

Error when attempting to write to a null socket

Open
#1,154 2 comments 2 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

A user has reported this error crashing the server.

file:///usr/local/lib/node_modules/postgres/src/connection.js:255
      const x = socket.write(chunk, fn)
                       ^
  TypeError: Cannot read properties of null (reading 'write')
      at Immediate.nextWrite (file:///usr/local/lib/node_modules/@rocicorp/zero/node_modules/postgres/src/connection.js:255:22)
      at process.processImmediate (node:internal/timers:485:21)
      at process.callbackTrampoline (node:internal/async_hooks:130:17)
  Node.js v22.15.0

This appears to point to this line of code: https://github.com/porsager/postgres/blob/5c8135f3df1bb10e7aad10f14a6f084db3724f82/src/connection.js#L255

The only other helpful information from our logs is the fact that the server was heavily loaded and requests to other services were timing out.

Is this a known issue and is there anything we can do to investigate how this happens (or how to prevent it)?

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 in src/connection.js around line 255 and trace how the socket can be null when nextWrite runs. Use the reported stack trace and the heavy-load and timeout details to identify reproducible conditions. Done means explaining the failure path and documenting or testing a reliable prevention, if the investigation supports one.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, postgresql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.