EMSGSIZE
Linux / POSIXERRORCommonNetworkHIGH confidence

Message Too Long

Production Risk

Common with UDP-based protocols; implement application-level fragmentation or use TCP.

What this means

EMSGSIZE (errno 90) is returned when a message sent via a socket exceeds the maximum size allowed by the protocol or the underlying network.

Why it happens
  1. 1Sending a UDP datagram larger than the MTU (typically 1500 bytes) without fragmentation
  2. 2Sending a message larger than the socket send buffer
  3. 3Sending on SOCK_DGRAM with IP_DONTFRAG set and message exceeds path MTU
How to reproduce

UDP send with a 65KB payload when MTU is 1500.

trigger — this will error
trigger — this will error
char buf[65535];
memset(buf, 'x', sizeof(buf));
// UDP datagram too large for MTU
sendto(sockfd, buf, sizeof(buf), 0,
       (struct sockaddr*)&dest, sizeof(dest));
// Returns -1, errno = EMSGSIZE

expected output

sendto: Message too long (EMSGSIZE)

Fix 1

Fragment large messages at application level

WHEN When sending large UDP payloads

Fragment large messages at application level
// Split into chunks ≤ 1400 bytes (leaves room for headers)
#define CHUNK_SIZE 1400
for (size_t offset = 0; offset < len; offset += CHUNK_SIZE) {
  size_t chunk = (len - offset < CHUNK_SIZE) ? len - offset : CHUNK_SIZE;
  sendto(sockfd, buf + offset, chunk, 0,
         (struct sockaddr*)&dest, sizeof(dest));
}

Why this works

Application-level fragmentation keeps each datagram within the path MTU.

Fix 2

Switch to TCP for large messages

WHEN When message size is variable and can exceed MTU

Switch to TCP for large messages
// TCP handles fragmentation automatically
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
connect(sockfd, (struct sockaddr*)&dest, sizeof(dest));
send(sockfd, buf, len, 0);

Why this works

TCP automatically segments messages; no EMSGSIZE errors.

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors