I'm seeing a situation where I have a TCP socket (non-blocking) that I'm writing to, but under load it gets into a situation where it keeps returning EAGAIN. I know this because it stops processing, and I can attach a debugger and step through it. Stepping through, the write call returns an error and errno is set to EAGAIN every time (it busy-waits on EAGAIN...ignore that this is a bad idea :)
My understanding was that EAGAIN should only be returned on a write if the buffer is full, but I don't understand what would prevent it from draining and the write call eventually succeeding.
This is Ubuntu, Linux kernel 3.19.0-47-generic.
Ideas?
What is preventing it from draining is that the peer isn't reading as fast as you're writing. The peer's receive buffer fills, your send buffer fills, you can't write.
it busy-waits on EAGAIN...ignore that this is a bad idea
I can't ignore that. It's a bad idea. You're supposed to use select() in this specific circumstance to tell you when the socket becomes writable, not just loop mindlessly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With