You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pglite-socket: crash when creating a large enum value. #820
I have a large enum value within my application with approx 1400~ values.
When it runs as a single CREATE TYPE public.big_enum as ENUM the database crashes with 2025-10-18 21:22:47.645 GMT [0] FATAL: terminating connection because protocol synchronization was lost
However when I break the enum into individual:
ALTERTYPEpublic.big_enum ADD VALUE 'rf_0000002';
ALTERTYPEpublic.big_enum ADD VALUE 'rf_0000003';
The db executes them without a problem.
Steps to Repdroduce:
Create a schema.sql file with entries up to 1000 values:
Confirmed it works in PGLite with the following script:
import{PGlite}from'@electric-sql/pglite'asyncfunctionmain(){constdb=newPGlite()awaitdb.query(` CREATE TYPE public.big_enum AS ENUM ( 'rf_0000001', 'rf_0000002', ..... 'rf_0001000' );`)console.log("create big enum succeeded")letresult=awaitdb.query(` SELECT unnest(enum_range(NULL::public.big_enum)) AS value; `)console.log(`returned rows: ${result.rows.length}`)result=awaitdb.query(` CREATE TABLE public.enum_samples (id BIGSERIAL PRIMARY KEY, tag public.big_enum NOT NULL) `)console.log("created test table")constlabels=Array.from({length: 1000},(_,i)=>`rf_${String(i+1).padStart(7,'0')}`);constplaceholders=labels.map((_,i)=>`(CAST($${i+1} AS public.big_enum))`).join(', ');constlargeInsert=`INSERT INTO public.enum_samples (tag) VALUES ${placeholders}`;constres=awaitdb.query(largeInsert,labels);console.log(`Completed insert affected rows: ${res.affectedRows}`);}main();
I think that the TCP buffers need to be joined before this happens somehow? The max length of a PG message is defined by the 32bit length field, but each TCP packet is max 64k. Example with --debug=5:
Activity
tdrz commentedon Oct 19, 2025
Thank you for this @itsWill !
One thing to try out would be to do the same insert directly with PGlite (ie without the
pglite-server) and see if it still crashes.itsWill commentedon Oct 19, 2025
Confirmed it works in PGLite with the following script:
The issue is on the socket-server side.
tdrz commentedon Oct 19, 2025
Thank you @itsWill this helps!
Will try to address it in a timely manner.
[-]Database crash when creating a large enum value.[/-][+]pglite-socket: crash when creating a large enum value.[/+]electric-al commentedon Dec 9, 2025
I am also seeing a similar issue. Basically any statement >64k (0xffff bytes) gets split into 2 tcp packets, and this code line https://github.com/electric-sql/pglite/blob/main/packages/pglite-socket/src/index.ts#L111 sends it straight to be processed as raw request.
I think that the TCP buffers need to be joined before this happens somehow? The max length of a PG message is defined by the 32bit length field, but each TCP packet is max 64k. Example with --debug=5:
electric-al commentedon Dec 10, 2025
I will try to send a proper PR later, but this worked for me. This solves the error.
tdrz commentedon Feb 9, 2026
Probably will be fixed once #873 is deployed.
tdrz commentedon Mar 9, 2026
Done in #873