Skip to content

TypeError: null is not an object (evaluating 'socket.write') #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
evelant opened this issue May 12, 2025 · 0 comments
Open

TypeError: null is not an object (evaluating 'socket.write') #1066

evelant opened this issue May 12, 2025 · 0 comments

Comments

@evelant
Copy link

evelant commented May 12, 2025

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.

postgres/src/connection.js

Lines 249 to 254 in b0d8c8f

function nextWrite(fn) {
const x = socket.write(chunk, fn)
nextWriteTimer !== null && clearImmediate(nextWriteTimer)
chunk = nextWriteTimer = null
return x
}

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!

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

No branches or pull requests

1 participant