{"record":{"id":"29c676f1dba072f0","repo":"denoland/deno","slug":"err-socket-buffer-size","errorCode":"ERR_SOCKET_BUFFER_SIZE","errorMessage":"Could not get or set buffer size","messagePattern":"Could not get or set buffer size","errorType":"exception","errorClass":"NodeSystemError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/dgram.ts","lineNumber":1410,"sourceCode":"  newHandle.bind = oldHandle.bind;\n  newHandle.send = oldHandle.send;\n  newHandle[ownerSymbol] = self;\n\n  // Replace the existing handle by the handle we got from primary.\n  oldHandle.close();\n  state.handle = newHandle;\n}\n\nfunction bufferSize(self: Socket, size: number, buffer: boolean): number {\n  if (size >>> 0 !== size) {\n    throw new ERR_SOCKET_BAD_BUFFER_SIZE();\n  }\n\n  const ctx = {};\n  const ret = self[kStateSymbol].handle!.bufferSize(size, buffer, ctx);\n\n  if (ret === undefined) {\n    throw new ERR_SOCKET_BUFFER_SIZE(ctx as NodeSystemErrorCtx);\n  }\n\n  return ret;\n}\n\nfunction socketCloseNT(self: Socket) {\n  self.emit(\"close\");\n}\n\nfunction healthCheck(socket: Socket) {\n  if (!socket[kStateSymbol].handle) {\n    // Error message from dgram_legacy.js.\n    throw new ERR_SOCKET_DGRAM_NOT_RUNNING();\n  }\n}\n\nfunction stopReceiving(socket: Socket) {\n  const state = socket[kStateSymbol];","sourceCodeStart":1392,"sourceCodeEnd":1428,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/dgram.ts#L1392-L1428","documentation":"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.","triggerScenarios":"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.","commonSituations":"Tuning UDP receive buffers for high-throughput apps in Docker/Kubernetes where sysctls are not raised; values like 1 << 24 exceeding defaults.","solutions":["Use a size within system limits (check /proc/sys/net/core/rmem_max and wmem_max)","Catch the error and keep the current value from the getter as a fallback","Raise the system limit (sysctl -w net.core.rmem_max=...) or run the container with adjusted sysctls when large buffers are required"],"exampleFix":"// before\nsocket.recvBufferSize = 1 << 24; // 16 MiB, may exceed rmem_max\n\n// after\ntry {\n  socket.recvBufferSize = 1 << 24;\n} catch (err) {\n  if (err?.code !== 'ERR_SOCKET_BUFFER_SIZE') throw err;\n  console.warn('kernel refused buffer size, keeping', socket.recvBufferSize);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"function applyBufSize(socket, prop, wanted) {\n  try {\n    socket[prop] = wanted;\n  } catch (err) {\n    if (err?.code !== 'ERR_SOCKET_BUFFER_SIZE') throw err;\n    console.warn(`${prop}=${wanted} rejected by OS, keeping`, socket[prop]);\n  }\n}","preventionTips":["Size buffers within net.core.rmem_max / wmem_max (check with sysctl)","Treat buffer sizing as best-effort: verify with the getter after setting","In containers, set required sysctls in the pod spec rather than assuming host defaults"],"tags":["dgram","udp","socket-options","os-limits"],"backgroundTag":"socket-set-option-failed","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}