denoland/deno · error · NodeSystemError

ERR_SOCKET_BUFFER_SIZE

ERR_SOCKET_BUFFER_SIZE

Error message

Could not get or set buffer size

What it means

After passing the integer check, bufferSize() calls the native handle; if the getsockopt/setsockopt operation fails, the handle returns undefined and fills a context object, and the polyfill throws ERR_SOCKET_BUFFER_SIZE with system-error details. This is an OS-level failure to get or set SO_RCVBUF/SO_SNDBUF, not an argument problem.

Solutions

  1. Use a size within system limits (check /proc/sys/net/core/rmem_max and wmem_max)
  2. Catch the error and keep the current value from the getter as a fallback
  3. Raise the system limit (sysctl -w net.core.rmem_max=...) or run the container with adjusted sysctls when large buffers are required

Example fix

// before
socket.recvBufferSize = 1 << 24; // 16 MiB, may exceed rmem_max

// after
try {
  socket.recvBufferSize = 1 << 24;
} catch (err) {
  if (err?.code !== 'ERR_SOCKET_BUFFER_SIZE') throw err;
  console.warn('kernel refused buffer size, keeping', socket.recvBufferSize);
}
Defensive patterns

Strategy: try-catch

Try / catch

function applyBufSize(socket, prop, wanted) {
  try {
    socket[prop] = wanted;
  } catch (err) {
    if (err?.code !== 'ERR_SOCKET_BUFFER_SIZE') throw err;
    console.warn(`${prop}=${wanted} rejected by OS, keeping`, socket[prop]);
  }
}

Prevention

When it happens

Trigger: Requesting a size above the system maximum (net.core.rmem_max/wmem_max) in a container with locked sysctls; the socket handle being in a failing state; platform restrictions on socket options.

Common situations: Tuning UDP receive buffers for high-throughput apps in Docker/Kubernetes where sysctls are not raised; values like 1 << 24 exceeding defaults.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/29c676f1dba072f0. Report an issue: GitHub.

Appendix: source

Thrown at ext/node/polyfills/dgram.ts:1410

  newHandle.bind = oldHandle.bind;
  newHandle.send = oldHandle.send;
  newHandle[ownerSymbol] = self;

  // Replace the existing handle by the handle we got from primary.
  oldHandle.close();
  state.handle = newHandle;
}

function bufferSize(self: Socket, size: number, buffer: boolean): number {
  if (size >>> 0 !== size) {
    throw new ERR_SOCKET_BAD_BUFFER_SIZE();
  }

  const ctx = {};
  const ret = self[kStateSymbol].handle!.bufferSize(size, buffer, ctx);

  if (ret === undefined) {
    throw new ERR_SOCKET_BUFFER_SIZE(ctx as NodeSystemErrorCtx);
  }

  return ret;
}

function socketCloseNT(self: Socket) {
  self.emit("close");
}

function healthCheck(socket: Socket) {
  if (!socket[kStateSymbol].handle) {
    // Error message from dgram_legacy.js.
    throw new ERR_SOCKET_DGRAM_NOT_RUNNING();
  }
}

function stopReceiving(socket: Socket) {
  const state = socket[kStateSymbol];

View on GitHub (pinned to 9ad36f7a2c)