TypeError: null is not an object (evaluating 'socket.write')
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
I'm seeing the following crop up on my Sentry errors for my backend functions
TypeError: null is not an object (evaluating 'socket.write')
File "/node_modules/postgres/src/connection.js", line 250, col 15, in nextWrite
running postgres 3.4.5 on Bun 1.2.10 in production. Sorry this issue is so light on details, I don't have many yet, but I wanted to put this here in case others are running into the same thing and we can figure out a solution together.
This seems to happen more or less randomly with postgres running on Bun on fly.io connected to a supabase database. Looking at the code I'm not sure how socket could become null unexpectedly. It's only assigned null in closed so I wouldn't expect it to be writing to the socket if closed were already called.
I suspect maybe a bug in Bun, possibly with setImmediate? Any ideas about how this might happen?
I'm running postgres via Effect-ts sql-pg with the following options
database: "postgres",
url: Bun.env["SUPABASE_DB_URL"]!,
fetchTypes: false,
maxConnections: 15,
idleTimeout: `30 seconds`,
connectionTTL: `5 minutes`,
prepare: false
If this is too little information to be helpful or useful feel free to close the issue. I'm sorry it's vague!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/connection.js around nextWrite at line 250, then review the closed path that sets socket to null. Try to reproduce the intermittent failure using Bun 1.2.10, postgres 3.4.5, and the reported connection settings. Done means identifying the lifecycle race or documenting the missing evidence needed to isolate whether the cause is postgres.js or Bun.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bun, javascript, postgres
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100