1. 04 Oct, 2018 10 commits
    • Mark Williams's avatar
      Move shared_ptr_internals methods out of the class · 78d7cd51
      Mark Williams authored
      Summary:
      When they come before the explicit instantiations of Rob, icc fails to
      compile certain combintions of calls.
      
      Reviewed By: alexeyt
      
      Differential Revision: D10144943
      
      fbshipit-source-id: ce63a4d289f64d1d644b116ab99b45b9da013162
      78d7cd51
    • Kenny Yu's avatar
      Make TSAN aware of unlock_shared() called on a different thread in ObserverManager · 3cc2f315
      Kenny Yu authored
      Summary:
      `folly::SharedMutex` allows `unlock_shared()` to be called in a different thread from the one that locked it
      There are some places in folly that use this property.
      
      Example: In `ObserverManager`, the calling thread
      
      1. acquires the read lock
      2. then it schedules some async work and gives ownership of the lock guard to the lambda
      3. the thread that performs the async work will unlock the mutex
      
      However, this causes false positives for TSAN. It looks like this breaks TSAN's assumptions that a read-write mutex is always read locked and unlocked in the same thread.
      In the example above, TSAN thinks the calling thread in step (1) still owns the mutex, even though semantically the mutex is now owned by the thread in step (3).
      
      This results in false positives for running unit tests with an annotated version of `folly::SharedMutex`.
      TSAN reports a lock inversion between the `folly::Singleton vaule_.state_` mutex, and the read lock referenced in `ObserverManager`.
      
      To suppress this error, this change annotates ObserverManager to let TSAN know that the the thread in step 1 has dropped
      the lock, and the thread in step 3 now owns the lock.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D9797937
      
      fbshipit-source-id: c0e5277bb9cb2f404df8abd3c3d6ea4a16460c78
      3cc2f315
    • Kenny Yu's avatar
      Fix TSAN lock inversion with folly::RequestContext::setContext · b2a33051
      Kenny Yu authored
      Summary:
      TSAN flagged the following lock inversion below. The reason for this lock inversion
      is because of the following example usage:
      
      1. set request context B, save old one A (lock B, lock A)
      2. later on, reset request context back to A, get the old one back B (lock A, lock B)
      
      In the two calls, we always locked the the new context first, resulting
      in a lock inversion. The fix is to always acquire them in a consistent
      order using `folly::acquireLocked`
      
      TSAN report:
      
      ```
      WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=1574307)
        Cycle in lock order graph: M159 (0x7b1400000138) => M157 (0x7b14000000e8) => M159
      
        Mutex M157 acquired here while holding mutex M159 in main thread:
          #0 0x48f18c in AnnotateRWLockAcquired ??:?
          #1 0x315495 in folly::SharedMutexImpl<false, void, std::atomic, false>::lock_shared() ./folly/SharedMutex.h:385
          #2 0x1b0eb8 in folly::detail::LockTraitsImpl<folly::SharedMutexImpl<false, void, std::atomic, false>, (folly::detail::MutexLevel)1, false>::lock_shared(folly::SharedMutexImpl<false, void, std::atomic, false>&) ./folly/LockTraits.h:157
          #3 0x1b0e68 in std::integral_constant<bool, true> folly::LockPolicyShared::lock<folly::SharedMutexImpl<false, void, std::atomic, false> >(folly::SharedMutexImpl<false, void, std::atomic, false>&) ./folly/LockTraits.h:493
          #4 0x1d63a9 in LockedPtrBase ./folly/Synchronized.h:1026
          #5 0x1d6258 in LockedPtr ./folly/Synchronized.h:1326
          #6 0x1c9a17 in folly::SynchronizedBase<folly::Synchronized<folly::RequestContext::State, folly::SharedMutexImpl<false, void, std::atomic, false> >, (folly::detail::MutexLevel)1>::rlock() const ./folly/Synchronized.h:123
          #7 0x1c7530 in folly::RequestContext::setContext(std::shared_ptr<folly::RequestContext>) ./folly/io/async/Request.cpp:243
          #8 0x36a7b in folly::RequestContext::create() ./folly/io/async/Request.h:119
          #9 0x34916 in RequestContextScopeGuard ./folly/io/async/Request.h:269
      
        Mutex M159 previously acquired by the same thread here:
          #0 0x48f18c in AnnotateRWLockAcquired ??:?
          #1 0x315495 in folly::SharedMutexImpl<false, void, std::atomic, false>::lock_shared() ./folly/SharedMutex.h:385
          #2 0x1b0eb8 in folly::detail::LockTraitsImpl<folly::SharedMutexImpl<false, void, std::atomic, false>, (folly::detail::MutexLevel)1, false>::lock_shared(folly::SharedMutexImpl<false, void, std::atomic, false>&) ./folly/LockTraits.h:157
          #3 0x1b0e68 in std::integral_constant<bool, true> folly::LockPolicyShared::lock<folly::SharedMutexImpl<false, void, std::atomic, false> >(folly::SharedMutexImpl<false, void, std::atomic, false>&) ./folly/LockTraits.h:493
          #4 0x1d63a9 in LockedPtrBase ./folly/Synchronized.h:1026
          #5 0x1d6258 in LockedPtr ./folly/Synchronized.h:1326
          #6 0x1c9a17 in folly::SynchronizedBase<folly::Synchronized<folly::RequestContext::State, folly::SharedMutexImpl<false, void, std::atomic, false> >, (folly::detail::MutexLevel)1>::rlock() const ./folly/Synchronized.h:123
          #7 0x1c7516 in folly::RequestContext::setContext(std::shared_ptr<folly::RequestContext>) ./folly/io/async/Request.cpp:242
          #8 0x36a7b in folly::RequestContext::create() ./folly/io/async/Request.h:119
          #9 0x34916 in RequestContextScopeGuard ./folly/io/async/Request.h:269
      
        Mutex M159 acquired here while holding mutex M157 in main thread:
          #0 0x48f18c in AnnotateRWLockAcquired ??:?
          #1 0x315495 in folly::SharedMutexImpl<false, void, std::atomic, false>::lock_shared() ./folly/SharedMutex.h:385
          #2 0x1b0eb8 in folly::detail::LockTraitsImpl<folly::SharedMutexImpl<false, void, std::atomic, false>, (folly::detail::MutexLevel)1, false>::lock_shared(folly::SharedMutexImpl<false, void, std::atomic, false>&) ./folly/LockTraits.h:157
          #3 0x1b0e68 in std::integral_constant<bool, true> folly::LockPolicyShared::lock<folly::SharedMutexImpl<false, void, std::atomic, false> >(folly::SharedMutexImpl<false, void, std::atomic, false>&) ./folly/LockTraits.h:493
          #4 0x1d63a9 in LockedPtrBase ./folly/Synchronized.h:1026
          #5 0x1d6258 in LockedPtr ./folly/Synchronized.h:1326
          #6 0x1c9a17 in folly::SynchronizedBase<folly::Synchronized<folly::RequestContext::State, folly::SharedMutexImpl<false, void, std::atomic, false> >, (folly::detail::MutexLevel)1>::rlock() const ./folly/Synchronized.h:123
          #7 0x1c7530 in folly::RequestContext::setContext(std::shared_ptr<folly::RequestContext>) ./folly/io/async/Request.cpp:243
          #8 0x34b99 in ~RequestContextScopeGuard ./folly/io/async/Request.h:278
      
        Mutex M157 previously acquired by the same thread here:
          #0 0x48f18c in AnnotateRWLockAcquired ??:?
          #1 0x315495 in folly::SharedMutexImpl<false, void, std::atomic, false>::lock_shared() ./folly/SharedMutex.h:385
          #2 0x1b0eb8 in folly::detail::LockTraitsImpl<folly::SharedMutexImpl<false, void, std::atomic, false>, (folly::detail::MutexLevel)1, false>::lock_shared(folly::SharedMutexImpl<false, void, std::atomic, false>&) ./folly/LockTraits.h:157
          #3 0x1b0e68 in std::integral_constant<bool, true> folly::LockPolicyShared::lock<folly::SharedMutexImpl<false, void, std::atomic, false> >(folly::SharedMutexImpl<false, void, std::atomic, false>&) ./folly/LockTraits.h:493
          #4 0x1d63a9 in LockedPtrBase ./folly/Synchronized.h:1026
          #5 0x1d6258 in LockedPtr ./folly/Synchronized.h:1326
          #6 0x1c9a17 in folly::SynchronizedBase<folly::Synchronized<folly::RequestContext::State, folly::SharedMutexImpl<false, void, std::atomic, false> >, (folly::detail::MutexLevel)1>::rlock() const ./folly/Synchronized.h:123
          #7 0x1c7516 in folly::RequestContext::setContext(std::shared_ptr<folly::RequestContext>) ./folly/io/async/Request.cpp:242
          #8 0x34b99 in ~RequestContextScopeGuard ./folly/io/async/Request.h:278
      
      ```
      
      Reviewed By: igorsugak
      
      Differential Revision: D9797715
      
      fbshipit-source-id: a0f991ae0ec8f3e9d33af6e05db49eceaf3a5174
      b2a33051
    • Kenny Yu's avatar
      Fix TSAN lock inversion in VirtualEventBase and FiberManagerMap · 272a2e9a
      Kenny Yu authored
      Summary:
      There is a lock inversion between VirtualEventBase and the fibers library:
      
      1. During program shutdown, `GlobalCache::getImpl` acquires its `mutex_`, then it calls `VirtualEventBase::runOnDestruction` which acquires the SharedMutex on `onDestructionCallbacks_`
      2. During normal program execution, `VirtualEventBase::destroyImpl()` acquires the `onDestructionCallbacks_` lock and then invokes the user-supplied callbacks, which will invoke `GlobalCache::eraseImpl` and acquire `mutex_`
      
      The reason for this lock inversion is because in step 2, we are holding a mutex while invoking user-supplied callbacks.
      The fix is to NOT hold the lock while we invoke these callbacks.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D9797816
      
      fbshipit-source-id: 861a915f22138f0c8d3f8bca4d7bf4b9a0aa3d26
      272a2e9a
    • Kenny Yu's avatar
      Suppress noisy TSAN lock inversions in folly::Singleton · b7add7bc
      Kenny Yu authored
      Summary:
      When running tests with a TSAN-annotated version of folly::SharedMutex,
      I discovered at least 3 types of lock inversions in folly::Singleton code.
      These inversions are probably benign and deadlock is not possible, but we need to
      suppress these inversions to prevent too much noise from TSAN.
      
      Lock inversions:
      
      1. The users can supply arbitrary create() functions for Singletons. If the create() function
         happens to acquire a mutex, then this introduces a lock ordering from
         SingletonVault -> mutex. Later on, when the user code runs in normal operations, we might
         hold the mutex and try to create a singleton, resulting in the mutex -> SingletonVault ordering
      2. SingletonVault::destroyInstances() holds a mutex, and then invokes the user-supplied destroy()
         functions. In the user supplied destroy functions, we might attempt to create a singleton and
         acquire the lock in SingletonHolder, resulting in SingletonVault -> SingletonHolder lock ordering.
         In normal operations, whenever a singleton is created, we have the SingletonHolder -> SingletonVault
         lock ordering in createInstance()
      3. doEagerInit() holds the eagerInitSingleton mutex and then acquires the SingletonVault lock
         during createInstance(). addEagerInitSingleton() holds the SingletonVault lock and then acquires
         the eagerInitSingleton lock.
      
      The source of these errors is that we are invoking user-supplied callbacks while holding mutexes.
      However, these lock inversions cannot actually deadlock based on higher-level knowledge of folly::Singleton
      state transitions.
      
      To suppress these errors, use the new `folly::SharedMutexSuppressTSAN` mutex instead, which will
      not be annotated by TSAN. If we are not building with TSAN, then this mutex is equivalent to a normal
      `folly::SharedMutex`.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D9797988
      
      fbshipit-source-id: 82b5850fe189f7d1dcaca0e3562fabcfafd0cef5
      b7add7bc
    • Kenny Yu's avatar
      Annotate folly::SharedMutex with TSAN annotations · 2924934a
      Kenny Yu authored
      Summary:
      This diff adds TSAN annotations to `folly::SharedMutex` to allow TSAN to find
      lock inversions with this type of mutex. Note that only the WritePriority version
      is annotated, and the ReadPriority version is not. See the comments in the source code
      for an explanation of this.
      
      Some notes about how the annotation was done:
      
      - We always call the RELEASED annotations at the beginning of unlock(), and the ACQUIRED annotations at the end of lock().
        This prevents a double locking interleaving where thread 1 has unlocked it and before RELEASED is called, another thread
        has locked it and calls ACQUIRED first.
      - These annotations treat upgrade locks as equivalent to a shared lock. This prevents any false positives, and keeps
        the annotations simple.
      - We need to keep the constructor for SharedMutex as `constexpr` to avoid static initialization bugs. As a result, we need
        to lazily annotate creation of the mutex. To do this, this adds an extra bit to the `SharedMutex` state to keep track if
        initialization has been called. In TSAN builds, we have an array of mutexes to enforce that initialization is called
        at most once.
      - This diff introduces a new template param AnnotateForThreadSanitizer (default is False). This allows users to use a new
        folly::SharedMutexSuppressTSAN version to avoid lock inversion detection if there are noisy lock inversions.
        However, this should be the exception and not the norm. In normal build modes, this is equivalent to a normal SharedMutex.
      
      Reviewed By: nbronson
      
      Differential Revision: D9677058
      
      fbshipit-source-id: b0f5719a75024937fb81672435fb1c9802f255d7
      2924934a
    • Kenny Yu's avatar
      Add TSAN annotation macros for shared mutexes · e71ead7b
      Kenny Yu authored
      Summary:
      This change is part of a bigger effort to make `folly::SharedMutex`
      compatible with TSAN so that TSAN can find lock inversions with these
      types of mutexes.
      
      In order to do this, we need to annotate the mutex function calls
      accordingly. The annotation functions are provided by the TSAN
      runtime library.
      
      Upcoming changes to `folly::SharedMutex`:
      
      1. provide annotation helper macros (this change)
      2. fix or suppress known issues in existing libraries (these macros will allow us to suppress issues)
      3. once all the issues are fixed, annotate `SharedMutex` accordingly
      
      Reviewed By: nbronson
      
      Differential Revision: D9797582
      
      fbshipit-source-id: 12306db98505fe31a8d8590113d10585840fbe6d
      e71ead7b
    • Nick Terrell's avatar
      Add AccessSpreader<>::cachedCurrent() · 03fe7209
      Nick Terrell authored
      Summary:
      `AccessSpreader::cachedCurrent()` caches the result of `AccessSpreader::getcpuFunc()` for 32 calls in a thread-local. The cached function takes 2 ns, where the current call takes 12 ns. This comes at the cost of being imprecise when threads migrate to a new cpu.
      
      I chose 32 as the number of calls because it only has a 10% overhead over never refreshing (2.05 ns vs 1.83 ns), where 16 has a 30% overhead, and it performs just as well as 64.
      
      Reviewed By: ot
      
      Differential Revision: D10151009
      
      fbshipit-source-id: 07ed292dfdcdcedcb74c24279f7773a80ad09348
      03fe7209
    • Nick Terrell's avatar
      Fix AccessSpreader tests and benchmarks · e0ec3bcd
      Nick Terrell authored
      Summary:
      * The atomic load was being optimized out of the benchmark.
      * The initializer wasn't being called for the test tags, so `AccessSpreader<ThreadLocalTag>::current()` and `AccessSpreader<PthreadSelfTag>::current()` were always returning 0.
      
      Reviewed By: ot
      
      Differential Revision: D10154155
      
      fbshipit-source-id: 76be9865c9ee591d24aedc64e6faf4fd24350282
      e0ec3bcd
    • Neel Goyal's avatar
      Remove NPN Support · 52b904f0
      Neel Goyal authored
      Summary: ALPN is the preferred way to do this.  We should only use that and not provide NPN support anymore.
      
      Reviewed By: knekritz
      
      Differential Revision: D10110626
      
      fbshipit-source-id: 5ec91fe51252bed0a8d8047e481df76a395e1286
      52b904f0
  2. 03 Oct, 2018 1 commit
    • Saif Hasan's avatar
      fix oss build · c42a131a
      Saif Hasan authored
      Summary:
      Two things
      - Use thenValue instead of then in one specific occurrence as later one has been deprecated
      - Build googletest on `release-1.8.1` as it is the one that compiles with c++11
      
      Reviewed By: cenzhao
      
      Differential Revision: D10178139
      
      fbshipit-source-id: 069578716e5e55ef0a25ea87e9ef5ceded1ff9d6
      c42a131a
  3. 02 Oct, 2018 2 commits
    • Wez Furlong's avatar
      enable O_CLOEXEC for /dev/urandom · 75e1242d
      Wez Furlong authored
      Summary: There's no need for this to be inheritable
      
      Reviewed By: yfeldblum
      
      Differential Revision: D10139559
      
      fbshipit-source-id: ae2db0d13e33c383fd73c0563b127e62e54a7094
      75e1242d
    • Dan Melnic's avatar
      Add IOBuf::takeOwnershipIov method · b7e06ff9
      Dan Melnic authored
      Summary: Add IOBuf::takeOwnershipIov method
      
      Reviewed By: yfeldblum, djwatson
      
      Differential Revision: D10135962
      
      fbshipit-source-id: 86a22d73aa1b72645640cf026d2dc2f38b02989c
      b7e06ff9
  4. 01 Oct, 2018 4 commits
    • Amol Bhave's avatar
      Use Heterogenous lookups for dynamic::getDefault · 1efbcb1b
      Amol Bhave authored
      Summary:
      Use heterogenous lookup for dynamic::getDefault for
      StringPiece/dynamic keys.
      
      Reviewed By: shixiao
      
      Differential Revision: D10127452
      
      fbshipit-source-id: 3cf28a28373211428ac5352136cf073e6c377b16
      1efbcb1b
    • Amol Bhave's avatar
      Add heterogenous operations in dynamic::setDefault · 1499c179
      Amol Bhave authored
      Summary:
      dynamic::setDefault already calls heterogenous `emplace(...)`, however it does not behave correctly for static constexpr strings.
      Add a specialization for StringPiece which solves this.
      
      The current set of tests does not invoke setDefault with an object as a key.
      This diffs adds a test that does that.
      
      Reviewed By: shixiao
      
      Differential Revision: D10007262
      
      fbshipit-source-id: 386a44bf6b0a24f81e843695d177d85b280b907d
      1499c179
    • Nathan Bronson's avatar
      document the interaction between insert and rehash · 18fce17c
      Nathan Bronson authored
      Summary: Document that insert may evaluate its arguments after rehashing.
      
      Reviewed By: shixiao
      
      Differential Revision: D10132409
      
      fbshipit-source-id: ba5996a309ae201ae08808272edd1fb0b981cc64
      18fce17c
    • Petr Lapukhov's avatar
      RFC 6902 - JSON Patch representation · b71b0675
      Petr Lapukhov authored
      Summary: Consume `folly::dynamic` and if it matches JSON patch format, build a sequence of patch operations. Application is to be done separately, e.g. by a method of `folly::dynamic` by walking the operations vector (obtained after parsing the patch) and applying operations to the document. This mimics the approach we used previously with `folly::json_pointer`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D10017234
      
      fbshipit-source-id: 1d0b9f0967e528b81abf7998c88abdaf70a2fce8
      b71b0675
  5. 30 Sep, 2018 4 commits
  6. 29 Sep, 2018 1 commit
    • Yedidya Feldblum's avatar
      Closer guarantee of constexpr Fingerprint tables computation · 2d042e64
      Yedidya Feldblum authored
      Summary: [Folly] Closer guarantee of `constexpr` Fingerprint tables computation. Works around a limitation that `template <...> constexpr` functions are only sometimes `constexpr` and may be non-`constexpr` for some instantiations with no warning by enforcing `constexpr` for the instantiations used.
      
      Differential Revision: D10116556
      
      fbshipit-source-id: f7014e5b2fce411c27c331874a7fd33841e14df3
      2d042e64
  7. 28 Sep, 2018 8 commits
    • Dan Melnic's avatar
      This fixes a linker issue · aa472be6
      Dan Melnic authored
      Summary: This fixes a linker issue
      
      Reviewed By: tuomaspelkonen
      
      Differential Revision: D10109866
      
      fbshipit-source-id: bf4193eafc8eb6f75b84241ff6e2ef89ef866642
      aa472be6
    • Neel Goyal's avatar
      Ensure SSL is initialized in getOpenSSLCipherNames · 4156360f
      Neel Goyal authored
      Summary: SSL_CTX_new can fail if OpenSSL is not initialized.  This ensures it is.
      
      Reviewed By: bolekk
      
      Differential Revision: D10105302
      
      fbshipit-source-id: 4da40d4714747b0e6a359a52fa594fc29bb93c0a
      4156360f
    • Andrii Grynenko's avatar
      Change makeObserver to compute the first value inline · f43ce6d6
      Andrii Grynenko authored
      Summary:
      Current thread was previously blocked waiting on the Future to be completed anyway, so there's no reason to not treat it like one of the ObserverManager threads (if it isn't one already) and run the computation inline.
      Without this change nested makeObserver calls could result in a deadlock if recursion depth was greater than the number of ObserverManager threads.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D10097363
      
      fbshipit-source-id: eb781ed5aea0ad9415da40fbc7f1c15ed481e92f
      f43ce6d6
    • HC Zhu's avatar
      Allow std::ignore in split() · a7937a66
      HC Zhu authored
      Summary:
      This allows a caller to throw away unwanted parts e.g.
      
      ```
      std::string user;
      folly::split('/', "ads_lla/admarket/adfox", std::ignore, user, std::ignore);
      
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D10057247
      
      fbshipit-source-id: 8198d4cb207bbd2007635db1e5796759dccf367c
      a7937a66
    • Anton Likhtarov's avatar
      Expose defaultValue() · 061ea836
      Anton Likhtarov authored
      Summary:
      SettingsMetadata provides a type-erased view, so the default value is stored as a string representation.
      This method allows getting the actual original default value.
      
      Differential Revision: D10077879
      
      fbshipit-source-id: 2c6bf15eba57da5cb33ad1c657bc9bd51bcd2946
      061ea836
    • Anton Likhtarov's avatar
      Move in global setting APIs into Snapshot · cf7517b8
      Anton Likhtarov authored
      Summary: This forces users to take a Snapshot and makes global settings updates both atomic and more explicit.
      
      Differential Revision: D10055254
      
      fbshipit-source-id: 73ce34acdadad19d5b75e74ad26f13dc7763228d
      cf7517b8
    • Anton Likhtarov's avatar
      Basic Snapshot functionality · 845a46cc
      Anton Likhtarov authored
      Summary:
      See the unit test for example usage.
      
      ```
      folly::settings::Snapshot snapshot;
      
      // Now changes to `FOLLY_SETTING(project, name)` and `snapshot(FOLLY_SETTING(project, name))`
      // are independent from each other.
      // Any updates to the settings in the snapshot can be published via snapshot.publish()
      ```
      
      Basic version with a global lock, there are ways to optimize this later.
      
      Differential Revision: D9926070
      
      fbshipit-source-id: 66ee7f28539c242a08b688eab4a18e4a42a8b0ff
      845a46cc
    • Yedidya Feldblum's avatar
      Various noexcept specifiers in IOBuf · 66a3d1c1
      Yedidya Feldblum authored
      Summary: [Folly] Various `noexcept` specifiers in `IOBuf`.
      
      Reviewed By: Orvid
      
      Differential Revision: D10081705
      
      fbshipit-source-id: 5516e7deca4edd50ea99e61e10cd413f3c0f17ae
      66a3d1c1
  8. 27 Sep, 2018 1 commit
    • Yedidya Feldblum's avatar
      Compute fingerprint tables at constexpr time · aaf9e970
      Yedidya Feldblum authored
      Summary: [Folly] Compute fingerprint tables at constexpr time, v.s. as a separate build step which generates a source file.
      
      Reviewed By: Orvid
      
      Differential Revision: D10081043
      
      fbshipit-source-id: f01f7587aafd29fc1c44515730b759325e1566d8
      aaf9e970
  9. 26 Sep, 2018 4 commits
    • Teng Qin's avatar
      ElfFile: unmap on init error · 1d10cf85
      Teng Qin authored
      Summary: Currently for `ElfFile::openNoThrow`, if `init` fails (due to mal-formatted content etc.) it won't unmap and close the file. They will only be unmapped / closed on destruction. This Diff calls `reset()` on that case.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D9997690
      
      fbshipit-source-id: c30907fb793c813a5ad40d249919dd1752a2d711
      1d10cf85
    • Jun Wu's avatar
      Use a larger stack if sigaltstack is too small · fc36aa9f
      Jun Wu authored
      Summary:
      The signal handler might use nearly 9KB stack for symbolization. That would
      cause stack overflow if the signal handler is running on a small alternative
      stack set by sigaltstack. We have seen that in Rust programs. The Rust stdlib
      sets up [8KB](https://github.com/rust-lang/libc/blob/4bd52f5e3ef5d6c8abdd1fbaf7c9975800a0dc93/src/unix/notbsd/linux/other/b64/x86_64.rs#L505) stacks [using sigaltstack](https://github.com/rust-lang/rust/blob/55b54a999bcdb0b1c1f42b6e1ae670beb0717086/src/libstd/sys/unix/stack_overflow.rs#L173) for all threads created by Rust on x64 Linux.
      
      Talked with jsgf, we'd still like to get a nice symbolized stack trace if
      segfault happens in a binary including both Rust and C++ code, since it's
      more likely the C++ part being wrong, so C++ symbol demangling is more
      important than Rust demangling.
      
      This diff detects the small sigaltstack case, then allocates larger stack for
      symbolization. Note the stack manipulation logic is not signal-safe, so it's
      not used for non-small-sigaltstack cases. Programs not using sigaltstack, or
      use sigaltstack with >9KB stacks won't be affected.
      
      As we're here, teach the signal handler to save and restore errno. Also add
      a note about golang's SA_ONSTACK requirement.
      
      Reviewed By: luciang
      
      Differential Revision: D9846902
      
      fbshipit-source-id: f0dc81b1c1249d8a724e112906e0ff0b14c14ea9
      fc36aa9f
    • Andrii Grynenko's avatar
      Possible deadlock with InlineTask and Mutex · d62c61c5
      Andrii Grynenko authored
      Summary: This demonstrates a deadlock that's possible when using InlineTask.
      
      Reviewed By: lbrandy
      
      Differential Revision: D9883432
      
      fbshipit-source-id: 45bb14181f6cfec41851315c0369232a30ba13d9
      d62c61c5
    • Neel Goyal's avatar
      Clear error stack in unsetNextProtocols · 6c70bf25
      Neel Goyal authored
      Summary:
      It seems like memdup may fail in certain builds with nullptr, 0 and cause OpenSSL to put a malloc failure on the stack.  See https://github.com/openssl/openssl/blob/master/ssl/ssl_lib.c#L2752
      
      This diff clears the error stack when we do this.
      
      Reviewed By: knekritz
      
      Differential Revision: D10037676
      
      fbshipit-source-id: ea7b136cafde818564e8ee2401f0cef30f52a45d
      6c70bf25
  10. 25 Sep, 2018 4 commits
    • Andrii Grynenko's avatar
      Add support for returning SemiFuture/Future from defer functor · 2b1e8dc5
      Andrii Grynenko authored
      Summary: Because DeferredExecutor now acts as a simple proxy to user executor, we can actually support multi-hop SemiFutures.
      
      Reviewed By: LeeHowes
      
      Differential Revision: D9928793
      
      fbshipit-source-id: c7e030bac3582b2931bc9639c766a4398ce23a76
      2b1e8dc5
    • Amol Bhave's avatar
      use heterogenous operations for get_ptr(dynamic) · c09be5f4
      Amol Bhave authored
      Summary:
      This diff adds support for doing heterogenous lookups
      to the dynamic::get_ptr(dynamic) function.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D10007208
      
      fbshipit-source-id: 2453f3fe8ab36dfd9e5627aa75cf8eb7aee51699
      c09be5f4
    • Andrii Grynenko's avatar
      Simplify DeferredExecutor · bdb2a715
      Andrii Grynenko authored
      Summary: Move the wait() and timed_wait() functionality out of DeferredExecutor. This is now possible because folly::Futures are using Executor::KeepAlive to manage executors' life-time.
      
      Reviewed By: LeeHowes
      
      Differential Revision: D9925417
      
      fbshipit-source-id: e9818417048f44ee66648439e781060fdabca6b9
      bdb2a715
    • Alexey Kozhevnikov's avatar
      Fix futures MSVC compilation issue · e3f27085
      Alexey Kozhevnikov authored
      Summary:
      MSVC (14.12.25827, VS 2017 15.5) fails to compile with internal error when using `/std:c++14` parameter:
      ```
      Future-inl.h(1484): fatal error C1001: An internal error has occurred in the compiler.
      (compiler file 'msc1.cpp', line 1507)
       To work around this problem, try simplifying or changing the program near the locations listed above.
      ```
      
      Reviewed By: yfeldblum, Orvid
      
      Differential Revision: D10018915
      
      fbshipit-source-id: ba886265b68684aacc2bf471c79ba6c39e611c8e
      e3f27085
  11. 24 Sep, 2018 1 commit
    • Philip Pronin's avatar
      make parallel generator movable · 0964862b
      Philip Pronin authored
      Summary:
      If `Source` isn't copyable, parallel generator cannot be composed
      further due to implicitly deleted move ctor.
      
      Example:
      
      ```
      byLines(File(...))
      | parallel(map(...))
      | sum;
      ```
      
      Reviewed By: ddrcoder, ot
      
      Differential Revision: D10004477
      
      fbshipit-source-id: 51ce23e834413bd53547a683f8ed89a1811f74a2
      0964862b