No buffer space available when write to socket

I'm getting error "No buffer space available" when I try to write to UDP socket with "write()" function. This only happens when I have heavy load and need to write data to socket very quick. Is there any way to get more information about this error? Why it happen and how to avoid it?

Answered by DTS Engineer in 124869022

So it's not bug but some kind of feature?

Well, it’s a feature in that:

  • it’s documented behaviour (see the list of return values in the man page for

    write
    )
  • an error is better than running the kernel completely out of memory

However, I’ll agree that, as an API, it is less than ideal. This is a common theme when programming with BSD Sockets, at least in my experience.

… or we should create new socket?

The socket is fine; you don’t have to recreate it.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

This is a form of send-side flow control. The kernel has run out of memory for use with your socket. You should handle this the same way you handle other forms of UDP send-side flow control. This is one of the standard gotchas you buy in to when you decide to use UDP as opposed to TCP.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

So it's not bug but some kind of feature? We need to wait for sometime and kernel will have memory for socket again or we should create new socket?

Accepted Answer

So it's not bug but some kind of feature?

Well, it’s a feature in that:

  • it’s documented behaviour (see the list of return values in the man page for

    write
    )
  • an error is better than running the kernel completely out of memory

However, I’ll agree that, as an API, it is less than ideal. This is a common theme when programming with BSD Sockets, at least in my experience.

… or we should create new socket?

The socket is fine; you don’t have to recreate it.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
No buffer space available when write to socket
 
 
Q