---
title: "When LIMIT 9 works but LIMIT 10 hangs"
description: "A Postgres query over Neon's serverless driver hung only when its WebSocket payload reached 126 bytes, the threshold where WebSocket framing switches to a 16-bit extended length field."
url: "https://swe.quest/articles/when-limit-9-works-but-limit-10-hangs-7b201245bb9c1182"
canonical: "https://neon.com/blog/when-limit-9-works-but-limit-10-hangs"
source: "Neon"
published: "2023-05-30"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 11
tags: ["debugging","javascript","networking","postgres","performance"]
---

# When LIMIT 9 works but LIMIT 10 hangs

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-05-30, 11 min read, Deep dive. Original: [https://neon.com/blog/when-limit-9-works-but-limit-10-hangs](https://neon.com/blog/when-limit-9-works-but-limit-10-hangs)

## Summary

A Postgres query over Neon's serverless driver hung only when its WebSocket payload reached 126 bytes, the threshold where WebSocket framing switches to a 16-bit extended length field. The cause was in undici's frame encoder, which wrote that length with a DataView over the buffer's backing ArrayBuffer at offset zero. Buffer.allocUnsafe() hands out small buffers as slices of a shared 8 KB pool, so the length bytes held garbage and the real length was written over other live buffers. The fix used writeUInt16BE(), shipped in undici 5.22.1, and a benchmark showed it is more than twice as fast as the DataView "optimization".

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Debugging](https://swe.quest/tags/debugging.md) (Engineering practices)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Networking](https://swe.quest/tags/networking.md) (Infrastructure)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- Node.js Buffers ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- WebSocket basics
- Wireshark packet capture

## Keywords

undici, WebSocket, Neon serverless driver, Wireshark, Buffer.allocUnsafe, DataView, Node.js, RFC 6455

## Related posts

- [Quicker serverless Postgres connections](https://swe.quest/articles/quicker-serverless-postgres-connections-7a37a1071edd4362.md): Neon · 2023-03-28 · Medium · 8 min read · PostgreSQL, Networking, Serverless, Performance engineering, Cryptography
  Neon cut the network round-trips needed to get a first query result from its WebSocket-based serverless Postgres driver from nine to four.
- [Edge-compatible Serverless Driver for Postgres](https://swe.quest/articles/edge-compatible-serverless-driver-for-postgres-9b0d09c6c7a067d0.md): Neon · 2022-12-08 · Medium · 9 min read · PostgreSQL, Serverless, Networking, Cryptography, WebAssembly
  Neon's @neondatabase/serverless driver lets V8-isolate platforms like Cloudflare Workers, which lack TCP, speak the real Postgres wire protocol by tunnelling it over a WebSocket to an open-source Go proxy that relays to TCP.
- [Using Neon’s Scale to Zero with Long-Running Applications](https://swe.quest/articles/using-neon-s-scale-to-zero-with-long-running-applications-bbe64dd8466d86d8.md): Neon · 2024-01-24 · Medium · 7 min read · PostgreSQL, Serverless, Resilience, JavaScript, Performance engineering
  Neon's scale to zero suspends a Postgres compute after an idle window (only when no WAL senders are active and autovacuum isn't running), which severs connections held by long-running servers.
- [Bun v1.1.23](https://swe.quest/articles/bun-v1-1-23-54b3cfbcfb783a45.md): Bun · 2024-08-14 · Medium · 7 min read · JavaScript, Runtimes & VMs, Performance engineering
  Bun v1.1.23 fixes 27 bugs and adds TextEncoderStream/TextDecoderStream, the TextDecoder stream option, Float16Array, and truncation of large arrays in console.log after 100 elements. console.log(string) is 50% faster: a single-string fast path that still needed extra writes for the newline and ANSI reset was dropped in favor of buffered writes.
- [Bun v1.2.18](https://swe.quest/articles/bun-v1-2-18-58157b3ac1570ec2.md): Bun · 2025-07-03 · Medium · 13 min read · JavaScript, Runtimes & VMs, Performance engineering
  Bun v1.2.18 fixes 52 issues and adds ReadableStream .text()/.json()/.bytes()/.blob(), ReadableStream stdin for Bun.spawn, permessage-deflate compression for the WebSocket client, and Math.sumPrecise.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
