1. 15 Dec, 2020 3 commits
    • Pranjal Raihan's avatar
      Expose folly::observer::waitForAllUpdates as public API · 0cb5aa0f
      Pranjal Raihan authored
      Summary:
      In most cases, `folly::observer::waitForAllUpdates` should not be needed. However, the asynchronous nature of observers break some basic assumptions that most users expect. Such as:
      ```
      thing.set(value);
      EXPECT_EQ(thing.get(), value);
      ```
      If `thing` is using `folly::observer` underneath the hood, the asynchrony is passed on to the user which is very easy to overlook, leading to bugs. The API of `thing` might want to enforce that when `thing.set` returns, all observed values will have been updated.
      Blocking is a perfectly okay solution in cases we don't expect an observer to be updated frequently.
      
      Differential Revision: D25542376
      
      fbshipit-source-id: c83909807fbf36e0311a45b667da94c43751a1da
      0cb5aa0f
    • Shai Szulanski's avatar
      Add co_result support to AsyncGenerator · e8aa07ff
      Shai Szulanski authored
      Summary: Mirrors Task. One behavioral difference is that yielding an empty Try from a Task converts into a UsingUninitializedTry exception, while for AsyncGenerator it converts into a return. This is for consistency with Thrift's ClientBufferedStream to avoid confusing users, but there is also an argument for converting to UsingUninitializedTry instead.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25379361
      
      fbshipit-source-id: 2a2878185696566b29345c99fee7ba74bef4ae8a
      e8aa07ff
    • Pranav Thulasiram Bhat's avatar
      Python error handling · 41f4344c
      Pranav Thulasiram Bhat authored
      Summary:
      This diff introduces a generic abstraction to convert a python error (set by a C-API call) into an informative C++ exception.
      
      The main motivation for this is to improve the error handling behavior when dealing with failed cython api module imports.
      
      This diff adds one callsite to the new abstraction in fiber.cpp  to demonstrate its usage.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25469594
      
      fbshipit-source-id: e9f83c06460f35fa76030ceae9726297276db850
      41f4344c
  2. 14 Dec, 2020 1 commit
    • Daan De Meyer's avatar
      Extend AsyncPipe with SingleProducer template parameter. · ab42eb8f
      Daan De Meyer authored
      Summary:
      When SingleProducer is disabled, AsyncPipe's method becomes thread-safe
      and can be called by multiple threads simultaneously. This is useful
      in a use case where a long running operation is being executed by
      multiple threads that all want to post status updates to the same
      AsyncPipe instance.
      
      Reviewed By: iahs
      
      Differential Revision: D25494695
      
      fbshipit-source-id: 1d0a74ec69dc8f64c171e21be612d211919cda4b
      ab42eb8f
  3. 12 Dec, 2020 1 commit
  4. 11 Dec, 2020 7 commits
    • Yu Zhao's avatar
      Fix mutex lock issue at the end of tsan test · f0bada9d
      Yu Zhao authored
      Summary:
      During tsan test, sometimes annotationGuard() is called after kAnnotationMutexes is already destroyed which throws exception.
      This change fix the issue by uses Indestructible for kAnnotationMutexes, so that it is not destroyed.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25443571
      
      fbshipit-source-id: 69411a7edc4f96ba8c7d08bd29f87ab7b2ff78ae
      f0bada9d
    • Zino Benaissa's avatar
      Make folly::small_vector friendly to compiler optimizations · 66d50da2
      Zino Benaissa authored
      Summary:
      This includes several enhancements to folly::small_vector:
      
      Eliminate overhead accessing vector elements by making heap_ points to element 0 of the vector.  To get start address only dispatch is required as shown below:
      
           value_type* data () {
             // Dispatch between heap_ or internalStorage,
             return isExtern() ? heap_ : &internalStorage_;
           }
      
      Reorganize the implementation by recording if capacity is stored internally or on the heap in "size". As a result the maximum vector size is half smaller. This is the only visible behavior change of this PR. Assuming size is 64 bits then
        - bit63 determines if vector elements are stored in internalStorage_ or externally in the heap
        - bit62 determines if vector capacity is stored internally or on the heap
        - bit61..bit0 contain the size of the vector.
      
      Reduce the overhead of updating size buy adding incrementSize functions.
      
      Tune emplace_back function and vector initialization.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D24413105
      
      fbshipit-source-id: b447704832af9c734be51aa6d23b8cb4be69a8bf
      66d50da2
    • Pranjal Raihan's avatar
      Use SharedMutex instead of MicroLock in AtomicObserver · f1c0c3c1
      Pranjal Raihan authored
      Summary:
      The initialization of `folly::MicroLock` *looks* correct. MSAN instrumentation probably needs to be disabled in its implementation.
      
      Regardless, the main point of using `folly::MicroLock` was its low memory usage (1 byte). I'm now changing it to `folly::SharedMutex` (4 bytes) which will be the same size due to alignment. Although `folly::SharedMutex` is not ideal for write-only locks, we don't care too much about write performance here.
      
      Differential Revision: D25487925
      
      fbshipit-source-id: 4c30650cf22dafbdaa9fea0c2252d29caf477d54
      f1c0c3c1
    • Eric Niebler's avatar
      use folly::void_t instead of std::void_t · 5e2a41e9
      Eric Niebler authored
      Summary: folly/Traits.h defines a `void_t` alias in the `folly::` namespace. Just use that instead of specifying the one in `std::`.
      
      Reviewed By: ispeters
      
      Differential Revision: D25483712
      
      fbshipit-source-id: 6be0435dfec600690cc90bc15fd3d2af17826173
      5e2a41e9
    • Misha Shneerson's avatar
      Allow Consumer of AtomicNotificationQueue to manage folly::RequestContext · c5d7abd5
      Misha Shneerson authored
      Reviewed By: prshreshtha
      
      Differential Revision: D25387330
      
      fbshipit-source-id: 027e04024e01d1eab938d67a2d1dfc93c9322b15
      c5d7abd5
    • Pranav Thulasiram Bhat's avatar
      Simplify getFiberManager · ebb18e1e
      Pranav Thulasiram Bhat authored
      Summary: The call-once logic in getFiberManager was unnecessarily complex. getFiberManager should only be called on main context, so use a static var initialization to implement the call-once logic (using executor.cpp as an example).
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25467655
      
      fbshipit-source-id: c880b1740edf28944e772c9310f3e45f5612396d
      ebb18e1e
    • Pranav Thulasiram Bhat's avatar
      Support multiple inputs to ShallowCopyScopeGuard · 33a42353
      Pranav Thulasiram Bhat authored
      Summary:
      With the current constructor setup, overwriting multiple request datas involves chaining together multiple ShallowCopyScopeGuard. This is quite inefficient as it involves copying the requests-data/callbacks maps multiple times.
      
      This diff introduces a new variadic constructor that accepts RequestDataItems (named pair of token and data)
      
      Reviewed By: A5he
      
      Differential Revision: D25317291
      
      fbshipit-source-id: 8a9cb00a615ecf802f22727189e4dc5a0c056c73
      33a42353
  5. 10 Dec, 2020 14 commits
    • Claire (Yue) Zhang's avatar
      Change AsyncSocket::UniquePtr destructor to ReleasableDestuctor · 7d9dbc59
      Claire (Yue) Zhang authored
      Summary: Adding a new ReleasableDestructor and use it in `folly::AsyncSocket::UniquePtr`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25352913
      
      fbshipit-source-id: b85204688706cb82a323e37063c9a6a390ec2ee8
      7d9dbc59
    • Pranjal Raihan's avatar
      Make SimpleObservable<T> default-constructible if T is default-constructible · a484d190
      Pranjal Raihan authored
      Summary: This simplifies generic code.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D25164246
      
      fbshipit-source-id: 4f42a2360f7ce32978360ddad63d1ca9512e6135
      a484d190
    • Pranjal Raihan's avatar
      Make SimpleObservable::getObserver const · 2e214867
      Pranjal Raihan authored
      Summary: Even though `SimpleObservable<T>::getObserver` lazily creates the observer, it has no side-effects and so it can be `const`.
      
      Differential Revision: D25146628
      
      fbshipit-source-id: f7d850aed5748a81c7cf083d489ca0d2c58be72c
      2e214867
    • Pranjal Raihan's avatar
      Allow AsyncServerSocket::setQueueTimeout to accept an Observer · ccc65a2e
      Pranjal Raihan authored
      Summary: `AsyncServerSocket::getQueueTimeout` also returns an `Observer` now.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D25146630
      
      fbshipit-source-id: 106ffc744eb6a3c09625897e72484054e0330247
      ccc65a2e
    • Pranjal Raihan's avatar
      Use thread_local instead of FOLLY_TLS in folly::observer · 2e32138d
      Pranjal Raihan authored
      Summary:
      `FOLLY_TLS` is explicitly disabled for 32-bit iOS. Perhaps because old iOS versions did not support `__thread`.
      
      `thread_local` is standard C++11, appears to be supported by the iOS 32-bit build, and is also used in multiple places around folly already.
      
      Differential Revision: D25287484
      
      fbshipit-source-id: 2e81e275e0f1cba7bcf5239fe34d4b5eb8add6d0
      2e32138d
    • Pranjal Raihan's avatar
      Add AtomicObserver<T> · 2ae32be7
      Pranjal Raihan authored
      Summary:
      An `AtomicObserver` is a read-optimized cache for an `Observer` value using `std::atomic`. This avoids creating a `shared_ptr` on every read (atomic increment/decrement on control block). The functionality is similar to that of `TLObserver` but uses significantly less memory if `std::atomic<T>` is valid.
      
      The read path involves 2 atomic loads and a cache staleness check. A lock is used when the cache needs to be updated.
      
      Reviewed By: zhxchen17
      
      Differential Revision: D25254487
      
      fbshipit-source-id: cfaf7c328c075f9f06c5c9d2d7bb2e1987285616
      2ae32be7
    • Andrew Huang's avatar
      Add the ability to turn on non-DHE resumption for clients in TLS 1.3 · 48380667
      Andrew Huang authored
      Summary:
      Add API to allow clients to advertise support for psk_ke (non-DHE) resumption. Unfortunately, OpenSSL has no option to allow servers to support psk_ke resumption.
      
      SSL_OP_ALLOW_NO_DHE_KEX option was added in OpenSSL 1.1.1, so add the appropriate guard.
      
      Reviewed By: mingtaoy
      
      Differential Revision: D24546720
      
      fbshipit-source-id: fd7c5b3a9f4c572876f9b421ee8f74ba7d5e252c
      48380667
    • Misha Shneerson's avatar
      split AtomicNotificationQueue into pure queue and event base driven queue · 3a1cb2bc
      Misha Shneerson authored
      Summary:
      EventBaseAtomicNotificationQueue is now what used to be just AtomicNotificationQueue.
      In the future, this allows reusing AtomicNotificationQueue with other types of executors.
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D24878180
      
      fbshipit-source-id: d719e31c7194cb2dd6d57a103814581b802a9250
      3a1cb2bc
    • Shai Szulanski's avatar
      Add conversions between folly and std optional · f8c8b74f
      Shai Szulanski authored
      Summary: These are similar enough that implicit conversion to make the migration boundary easy to manage seems justified
      
      Reviewed By: WillerZ
      
      Differential Revision: D25384005
      
      fbshipit-source-id: 4602d9016919860ff0626de4fa4ae5442fca094a
      f8c8b74f
    • Andrew Huang's avatar
      Add ability to set TLS 1.3 ciphersuites in SSLContext · a247041e
      Andrew Huang authored
      Summary: Add support for Openssl's TLS 1.3 ciphersuites API. SSL_CTX_set_ciphersuites was added in OpenSSL 1.1.1, so guard it with a prereq.
      
      Reviewed By: yfeldblum, mingtaoy
      
      Differential Revision: D24542765
      
      fbshipit-source-id: d281bb2262cd456823da1896c0c77c3ba4ab78ce
      a247041e
    • Eric Niebler's avatar
      Avoid using std::enable_shared_from_this on older stdlibs that don't support weak_from_this() · 9a1bfc69
      Eric Niebler authored
      Summary:
      Older standard libraries provide a `std::enable_shared_from_this` that doesn't have a `weak_from_this()` member, even when compiling in C++17 mode. Change the preprocessor conditional to account for this, and select the custom Folly implementation when the `std::` one is non-conforming.
      
      This change makes special accommodation for older MSVC versions, which fails to define the `__cpp_lib_enable_shared_from_this` feature test macro, but that provides a conforming `std::enable_shared_from_this` when compiling as C++17.
      
      Reviewed By: yfeldblum, ispeters
      
      Differential Revision: D25402425
      
      fbshipit-source-id: c53b9fcebbf93c54342824dd56fd11eaa681abd1
      9a1bfc69
    • Lee Howes's avatar
      Make retrying always return a SemiFuture · 175f274c
      Lee Howes authored
      Summary: Make futures::retrying return a SemiFuture and safely constrain where the work runs to avoid accidental inline execution.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D24490957
      
      fbshipit-source-id: 9b8c0f369084f2d26bbb4764abde6866fb09b4d9
      175f274c
    • Zeyi (Rice) Fan's avatar
      GitHub Action: fix Windows build · 1e90876e
      Zeyi (Rice) Fan authored
      Summary:
      Watchman's GitHub Action has been failing because of the use of `set-env` is deprecated due to security issues. See https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/ for details.
      
      See https://github.com/facebook/watchman/runs/1520165260?check_suite_focus=true for example of failures.
      
      To fix it we just need to write to the special environment file.
      
      Reviewed By: chadaustin
      
      Differential Revision: D25412442
      
      fbshipit-source-id: d31ef025189c8aebfa08d434d9373f5da7d4690e
      1e90876e
    • Lewis Baker's avatar
      Change Task::semi() to capture callsite of semi() in detached_task stack-trace · 5db8c175
      Lewis Baker authored
      Summary:
      The async stack-trace for a coroutine call-stack that was launched
      by calling Task<T>::semi() to create a SemiFuture would have as its
      first few frames:
      - detached_task
      - folly::coro::Task::semi::{lambda#1}::operator()
      - <the coroutine being launched>
      
      This isn't particularly useful as it doesn't tell you where the coroutine was launched from. The more interesting information here
      is the callsite of .semi() rather than the internals of .semi().
      
      This reworks the implementation of .semi() to capture the return-address
      of the call to .semi() and then later inject this as the return-address
      of the async-frame when the coroutine is eventually launched.
      
      Note: This also now launches the coroutine inline inside the SemiFuture by calling .startInlineImpl(). This should avoid an
      extra executor reschedule.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25415029
      
      fbshipit-source-id: ab24e86b871c78e2c3a9af843e24e2dab3254273
      5db8c175
  6. 09 Dec, 2020 1 commit
    • Dan Melnic's avatar
      IoUringBackend rework · cd39f451
      Dan Melnic authored
      Summary:
      IoUringBackend rework
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: kevin-vigor
      
      Differential Revision: D25287276
      
      fbshipit-source-id: b69cc715e8bf5da2e493a742e71a62795a62f955
      cd39f451
  7. 08 Dec, 2020 4 commits
    • Dan Melnic's avatar
      folly::ConcurrentHashMap::reserve() - avoid setting count to 0 · 8da5b759
      Dan Melnic authored
      Summary: folly::ConcurrentHashMap::reserve() - avoid setting count to 0
      
      Reviewed By: magedm
      
      Differential Revision: D25398175
      
      fbshipit-source-id: fc61b27d145f0d800cba9d35c942c0a5c8b53e2a
      8da5b759
    • Xiao Shi's avatar
      heterogeneous mutations for ConcurrentHashMap · cea6de83
      Xiao Shi authored
      Summary:
      This diff adds heterogeneous mutation support to ConcurrentHashMap.
      The gating of the allowed key types are done in `EnableHeterogeneousInsert`.
      
      `CHM::insert()` does not destructure `pair` arguments and `CHM::emplace()` does
      not yet attempt to identify a usable key, leaving those as future follow-ups.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25255528
      
      fbshipit-source-id: e056db05c96d3bd29c8cbce562ecd2221884cd5f
      cea6de83
    • Xiao Shi's avatar
      heterogeneous lookup for ConcurrentHashMap · 47a169a1
      Xiao Shi authored
      Summary:
      This diff adds heterogeneous lookup handling for `ConcurrentHashMap` (`find()`
      and `at()`), which allows lookups on keys that the hasher and key equal
      functors accept but are not exactly the same as the `KeyType` of the map.
      Common usage of the feature include looking up with a `std::string_view` key in
      a `map<string, X>`, thereby avoiding creating an unnecessary temporary string
      object.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25250409
      
      fbshipit-source-id: 78dad163d623794b179c1691180b54cf109784ee
      47a169a1
    • Andrew Huang's avatar
      Move test/SSLUtil into its own translation unit · 20006c60
      Andrew Huang authored
      Summary: Title, per the comments in D24542765
      
      Reviewed By: mingtaoy
      
      Differential Revision: D25339949
      
      fbshipit-source-id: a203dcd9ee4d2f3282d9d0f8706f8af9f084551c
      20006c60
  8. 07 Dec, 2020 2 commits
    • Xavier Deguillard's avatar
      rcu: narrow some variable to avoid warnings · bf3b5e1e
      Xavier Deguillard authored
      Summary:
      On Windows, MSVC rightfully complains about conversion from uint64_t to uint8_t
      and uint32_t. In both cases, the narrowing is acceptable, so let's do that.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25352231
      
      fbshipit-source-id: aa900fc14a666f1a99bfaa45b1afac02e7209fa3
      bf3b5e1e
    • Cameron Pickett's avatar
      Introduce CO_ASSERT macros to folly::coro · 90f2b499
      Cameron Pickett authored
      Summary: This change introduces CO_* versions of the main GTest ASSERT_* macros that we use in test validation. These are needed as calling ASSERT_* in a coroutine does not work. ASSERT_* embeds a `return` statement, while coroutines need a `co_return` statement.
      
      Reviewed By: ispeters
      
      Differential Revision: D25369376
      
      fbshipit-source-id: dbd95e8c21e28581f93202af4d6fea9245238f5d
      90f2b499
  9. 04 Dec, 2020 5 commits
    • Xiayi Sun's avatar
      folly: utf8ToCodePoint: enforce max valid code point is U+10FFFF - return... · ae03ef83
      Xiayi Sun authored
      folly: utf8ToCodePoint: enforce max valid code point is U+10FFFF - return U+FFFD / throw for well-formed UTF-8 encoded values that are larger than the max code point
      
      Summary:
      UTF-8 can encode large numbers, but Unicode code points are only defined up to `U+10FFFF`.
      
      For example:
      - the 4B UTF-8 encoding `"\xF6\x8D\x9B\ xBC"` (bits: `11110110 10001101 10011011 10111100`) is a valid UTF-8 encoding
      - but the encoded value is `U+18D6 (https://github.com/facebook/folly/commit/d40182262d41679cab28f6be7366cc5ff901683b)FC` which is larger than `U+10FFFF`
      
      With `opts.skip_invalid_utf8 = true;` `json::serialize` should have returned `"\ufffd"` since it the input is invalid, but due to a bug in `utf8ToCodePoint` it returned the incorrect `"\"\xF6\x8D\x9B\xBC\""`.
      
      Update `utf8ToCodePoint` to also reject 4 byte UTF-8 encoded values larger than the max Unicode code point (`U+10FFFF`).
      
      Reviewed By: luciang
      
      Differential Revision: D25275722
      
      fbshipit-source-id: e7daeea834a0c5323923a5451a2565ceff5e4734
      ae03ef83
    • Pierre Moulon's avatar
      Fix typo 'exmaple' -> 'example' · 67f20f29
      Pierre Moulon authored
      Differential Revision: D25307854
      
      fbshipit-source-id: 11b1282659b1b2c20b04e848f0c9824813af5b21
      67f20f29
    • Jun Mei's avatar
      Improve string to 32-bit float conversion near numeric limits · 4c2692fa
      Jun Mei authored
      Summary: This change introduces a specialization for string-to-float (32-bit) conversion. It improves fidelity to the numeric value represented by the input string.
      
      Reviewed By: vitaut
      
      Differential Revision: D25239226
      
      fbshipit-source-id: 531aa33aa74aaeeb98d9803bcd10bd7f31654988
      4c2692fa
    • Dan Melnic's avatar
      Fix the WriteOptions gso default value - it should be disabled · 5a2072f6
      Dan Melnic authored
      Summary: Fix the WriteOptions gso default value - it should be disabled
      
      Reviewed By: danobi
      
      Differential Revision: D25313187
      
      fbshipit-source-id: 581f41d9da48405092eef303630aaa88b18d1da0
      5a2072f6
    • Misha Shneerson's avatar
      keep asynchronous tasks on the intended thread pool - part I (executors) · ea2cb28e
      Misha Shneerson authored
      Summary:
      Today, a continuation of coro or semifuture application handlers will always execute on NORMAL priority thread pool. This is because the effective executor for the task is the `ThreadManager::Impl` and its `add()` implementation does not preserver tasks' priority (which we map into thread pool).
      
      In this change, we wrap each priority/source in a separate keepalive. Generated code is routing either coro or semifuture onto the corresponding keepalive, which is preserved across tasks that do not explicitly specify a target executor.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D25105971
      
      fbshipit-source-id: 9adaea654b3a099ff4de048026a67bdb588a3c2a
      ea2cb28e
  10. 03 Dec, 2020 2 commits
    • Pranjal Raihan's avatar
      Add folly::observer::makeStaticObserver · f7c36166
      Pranjal Raihan authored
      Summary: `makeStaticObserver` is a helper method that returns an observer that never changes in value.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D25254488
      
      fbshipit-source-id: 1336d0088aff1e5abfa8160bd76e4f61b68eaed8
      f7c36166
    • Jonathan Mendoza's avatar
      Get point-in-time TDigest snapshot from BasicQuantileStat · 5af34247
      Jonathan Mendoza authored
      Summary:
      This diff enables aggregation of point-in-time snapshots of the `TDigest`s that represents the state of `BasicQuantileStat`
      
      We capture a `Snapshot` of `TDigest` and `SlidingWindow<TDigest>`.
      
      The diff exposes `TDigest` and `SlidingWindow<TDigest>` to `QuantileStats`.
      
      These objects are wrapped by the structs, `Snapshot` and `SnapshotEntry`, in `BasicQuantileStat` and `BasicQuantileStatMap`, respectively .
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25170883
      
      fbshipit-source-id: 0201a05cc4020851b652ed3a7b602d5b22aa63be
      5af34247