robgjansen / libkqtime

A library that tracks the queuing time of bytes traveling through the kernel.
Other
3 stars 1 forks source link

interposed send() may tag data before kernel consumes it #1

Open robgjansen opened 10 years ago

robgjansen commented 10 years ago

In kqtime-preload.c here and here, the out handler is called on the data buffer the application is using, even though the kernel may not actually consume the entire buffer. This is a bug, because we may end up tagging data as entered the kernel before it actually did.

The fix is to follow the approach used on the recv() side, and only allow the data handler to look at what the kernel actually consumed.

robgjansen commented 9 years ago

The fix above introduced a potential race condition where libkqtime may notice that a tagged packet was sent out by the kernel before libkqtime notices that the tag was already written. So I deleted it.

Before, we called the outhandler first and send second, to make sure that libkqtime new about the tag before the tag was sent out on the wire by the kernel.

I think we still need to do it this way; except now, we should see if the kernel didn't read the part of the buffer where we took the tag, then we will need to send a "cancel" message to the search thread or overwrite the tag with a new tag on the next write.

robgjansen commented 9 years ago

We take the 16 byte tag at 200 bytes into the buffer, so this is only a problem when the kernel can't accept 216 bytes.