I’m testing some macOS code that’s doing TCP socket I/O with NSStreams. 
Occasionally (about one in ten runs) it’ll get stuck: no deadlocks or blocked 
threads or anything, it’s just completely idle even though the peer is still 
trying to send data. (The peer also gets stuck because its socket’s write 
buffer fills up.)

It looks like what’s happening is that my delegate object isn’t getting an 
NSStreamEventHasBytesAvailable event from the stream, even though there’s data 
to read. I’ve added logging when this event is received, and also at the point 
where I actually read from the stream, so I can tell that every byte-available 
event is followed by a read. (I know that if the read call doesn’t happen, the 
stream won’t send another event.) I’ve also located the NSInputStream instance 
and checked its hasBytesAvailable property in the debugger — it’s YES.

I’m not sure how this can happen. My understanding is that when I receive the 
bytes-available event I should read bytes from the stream, and even if I don’t 
read all the available bytes, I’ll get another event. Correct? The code was 
reading a max of 4kb from the stream; as an experiment I raised this to 16kb 
and I can’t get the bug to occur again. But I may just have made it less likely.

—Jens

PS: This is on macOS 10.12.4 Beta 1 (16E144f).
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (Macnetworkprog@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/macnetworkprog/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to