Fix zerocopy AsyncSocket memory leaks
authorDan Melnic <dmm@fb.com>
Fri, 15 Dec 2017 03:59:27 +0000 (19:59 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 15 Dec 2017 04:06:39 +0000 (20:06 -0800)
commit23e45679ddec0cc620ee6fedbb7891e488669bdd
treec7504bc75de45126ba156bc079076a02f00f4bc7
parentf5882bb6415b07aaa5d74199a16c610f6da7824c
Fix zerocopy AsyncSocket memory leaks

Summary:
We currently leak ptr entries due to a missing map erase call in AsyncSocket::releaseZeroCopyBuf.
Also addZeroCopyBuf called when the bytesWritten == 0 will cause and extra id to be allocated. This will delay the deletion of the last IOBuf sent via zerocopy. The number of buffers can accumulate over time if the same bytesWritten == 0 situation is encountered.
Found when running the nbd-server zero downtime upgrade during heavy fio traffic.
Add an AsyncSocket::processZeroCopyWriteInProgress so we can drain the zerocopy msg error queue even after we set the ReadCallback to nullptr.

Reviewed By: djwatson

Differential Revision: D6552982

fbshipit-source-id: 3d2fdca84ec3b5fc46c3bed06c0c9ede66ed565a
folly/io/async/AsyncSocket.cpp
folly/io/async/AsyncSocket.h
folly/io/async/test/ZeroCopy.cpp [new file with mode: 0644]
folly/io/async/test/ZeroCopy.h [new file with mode: 0644]
folly/io/async/test/ZeroCopyBenchmark.cpp
folly/io/async/test/ZeroCopyTest.cpp [new file with mode: 0644]