fix some bugs in AsyncSSLSocketTest Summary: A couple of the test functions in AsyncSSLSocketTest maintained two EventBase objects and alternated looping between them. In some cases it would call EventBase::loopOnce() even when there was no work to do. This call normally blocks until an event is ready. This happened to work when using libevent1, but this appears mostly accidental: with libevent1 EVLOOP_ONCE causes the loop to break out even after an "internal" I/O event; in libevent2 EVLOOP_ONCE only breaks out after a non-internal event has occurred: https://github.com/libevent/libevent/commit/0617a818204397790e5e4c9bcb9e91ae5ea7817a In these tests it turns out that the internal EventBase NotificationQueue always gets triggered the very first time loopOnce() is called, preventing these tests from hanging when using libevent1. This fixes the hang when using libevent2 by removing the initial loopOnce() calls that potentially have nothing to do. This also consolidates the 2 EventBase objects into one to avoid having to alternate loopOnce() calls between them without knowing which one actually has work to do. This also fixes an issue where the code never checked the return value of `recv()` Reviewed By: yfeldblum, siyengar Differential Revision: D6735669 fbshipit-source-id: 5f36106a08866aa8908e82263f83a606399cdf79
Loop Time Summary: Only do the exponential loop smoothing once every 10ms. If we need it before then, do it linearly. Also, remove one of the now()s by only calling it once. Reviewed By: bmaurer, yfeldblum Differential Revision: D6690047 fbshipit-source-id: 8267c01064aabc17cb8e86eb888e6120c99a129f
Revert D6725091: [Folly] Use thread-local in RequestContext::getStaticContext Summary: This reverts commit 9979f39677284b1051cb109b461097495d77ca17 bypass-lint An infra SEV is better than not reverting this diff. If you copy this password, see you in SEV Review! cause_a_sev_many_files Differential Revision: D6725091 fbshipit-source-id: f1e3c80c869aa47684f5fbe79528e68174dee568
Use thread-local in RequestContext::getStaticContext Summary: [Folly] Use thread-local in `RequestContext::getStaticContext`. `folly::SingletonThreadLocal` uses `folly::ThreadLocal`. However, `static FOLLY_TLS` (`static __thread`) is always faster than `folly::ThreadLocal` for thread-local singletons for which iteration is not required. Reviewed By: djwatson Differential Revision: D6725091 fbshipit-source-id: 9979f39677284b1051cb109b461097495d77ca17
Fix copyright lines Summary: [Folly] Fix copyright lines based on file histories. Reviewed By: spalamarchuk Differential Revision: D6720312 fbshipit-source-id: c70a667a1977e70e2d4451ea624f96163982f681
Return if we handle any error messages to avoid unnecessarily calling recv/send Summary: Return if we handle any error messages to avoid unnecessarily calling recv/send Reviewed By: yfeldblum Differential Revision: D6677314 fbshipit-source-id: 21f724bb2c92b954888ba97bf7820d72decd2775
give all folly exception types default visibility Summary: This makes sure that whether folly is statically or dynamically linked, all folly exception types will have exactly one definition, and one set of type information. Reviewed By: mzlee Differential Revision: D6671431 fbshipit-source-id: 1c06826a05f87cbf9af747c9abdb5f524744d054
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
Fix AsyncSocketTest.WriteErrorCallbackBytesWritten Summary: [Folly] Fix `AsyncSocketTest.WriteErrorCallbackBytesWritten`. Thanks to congestion, especially when the tests are run concurrently, the expectations in the test were too restrictive. If only 20KB are read, it is possible that only 20KB are acknowledged. The expectation was that if 20KB are read and the recv buffer and send buffer are both 8KB and 24KB are written then all 24KB are acknowledged, but congestion control disagrees. It is possible that any number of bytes are written to the send buffer, from 28KB up to 40KB. And we have to explicitly wait for 28KB to be written even to know that (otherwise we only know that 20KB are written). Differential Revision: D6550804 fbshipit-source-id: 100d086972c1526b909da0dbb6e609c144d7b17b
Explicitly refer to the std::chrono namespace to avoid conflicts with the folly::chrono namespace Summary: This is a hard requirement due to an upcoming change in Folly. The codemod was only run on files that referenced the `std::chrono` namespace with an unqualified `chrono` and also used both the `std` and `folly` namespaces. ``` fbgr -sl "[^:]chrono::" | xargs grep -l "using namespace std;" | xargs grep -l "using namespace folly;" | xargs sed -r -i 's/([^:])chrono::([a-z])/\1std::chrono::\2/g' ``` Reviewed By: yfeldblum Differential Revision: D6547864 fbshipit-source-id: 4a8230d311edbaa173722a09b2773e8d053fae7e
Switch to the try_wait_for and try_wait_until Baton APIs Summary: Switch to the `try_wait_for` and `try_wait_until` `Baton` APIs. Reviewed By: davidtgoldblatt Differential Revision: D6532103 fbshipit-source-id: aa3ce64152d167bb9c9cb1f266be0f9f8bd498f5
Fix case where ssl cert does not match key Summary: In some cases, SSLContextManager seg faults if a cert and key do not match. This guards against that case when strictSSL = false, and throws a more useful error in the cases when SSL is required. Reviewed By: xybu Differential Revision: D6513964 fbshipit-source-id: 8e63a22b346fd3f2a30d558a3659ab6794c7a105
Move folly/Bits.h to folly/lang/ Summary: [Folly] Move `folly/Bits.h` to `folly/lang/`. Reviewed By: phoad, Orvid Differential Revision: D6495547 fbshipit-source-id: a93159321df8277f8a4b4f10a5e4e0fc58cb6022
Move folly/Baton.h to folly/synchronization/ Summary: [Folly] Move `folly/Baton.h` to `folly/synchronization/`. Reviewed By: phoad, Orvid Differential Revision: D6490282 fbshipit-source-id: 66e2d25ffe3275d576b97b81c1987709000f6649