1. 21 Sep, 2016 1 commit
    • Shoaib Meenai's avatar
      Fix compilation for libc++ 3.9 · 60d9f847
      Shoaib Meenai authored
      Summary:
      libc++ 3.9 and above define the __throw* functions inside stdexcept, so
      defining them ourselves leads to compilation errors when compiling
      against libc++ 3.9. Add appropriate preprocessor guards to avoid this.
      
      Reviewed By: meyering
      
      Differential Revision: D3898284
      
      fbshipit-source-id: 435a28c2b3a83ee4d8f5af0df0343c524469011e
      60d9f847
  2. 20 Sep, 2016 6 commits
    • Subodh Iyengar's avatar
      Fix detaching from evb · 992ac3ae
      Subodh Iyengar authored
      Summary:
      When we attach and detach from the
      event base threads during connections
      in the case of SSL it could result in
      a crash while using TFO.
      
      When TFO was enabled connectTimeout_
      was set, which was not detached.
      
      In the case when we would
      fall back from TFO in case TFO did not
      succeed, we would try and schedule a
      connect timeout again. However because
      we are now scheduled in a new evb thread,
      this would cause the scheduleTimeout to
      assert that it was not in the correct evb
      thread.
      
      This fixes the issue by attaching and detaching
      connect timeouts as well.
      
      Reviewed By: ngoyal
      
      Differential Revision: D3892490
      
      fbshipit-source-id: 278c0b8029022144cd59366ceb0ce83f0a60a307
      992ac3ae
    • Sven Over's avatar
      use folly::Function<void()> in folly::Executor interface · 9ff27587
      Sven Over authored
      Summary:
      This diff changes the definition of `folly::Func` from `std::function<void()>`
      over to `folly::Function<void()>`. This mostly affects the interface of
      `folly::Executor` and derived and related classes. By using
      `folly::Function<void()>`, we allow to have lambdas capturing move-only types
      passed to executors. This continues an effort to get rid of the potentially
      dangerous `folly::MoveWrapper` by allowing to capture move-only types in lambdas
      when using `folly::Future`, `folly::EventBase` and now `folly::Executor`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3706449
      
      fbshipit-source-id: 11c2cee32cb9f0298c39b7b1695a477777eeb3aa
      9ff27587
    • Maged Michael's avatar
      Draft prototype of hazard pointers C++ template library · 6a5f4337
      Maged Michael authored
      Summary: Make draft of hazard pointers prototype public
      
      Reviewed By: djwatson
      
      Differential Revision: D3870280
      
      fbshipit-source-id: e029efa336585055f67687059e10ae11766f8d7f
      6a5f4337
    • Andrey Ignatov's avatar
      Remove boost::barrier from AsyncUDPSocketTest. · c821d129
      Andrey Ignatov authored
      Summary:
      `EventBase` has its own methods to wait till it's ready so we can avoid using
      barriers and remove boost dependency.
      
      Reviewed By: mzlee
      
      Differential Revision: D3894408
      
      fbshipit-source-id: f050a982c98c4f672cf295845115686c95fc7919
      c821d129
    • Igor Sugak's avatar
      Fix fibers asan integration for new asan APIs · 691cd11c
      Igor Sugak authored
      Summary:
      Updating fibers code to use https://github.com/llvm-mirror/compiler-rt/commit/b0477747dfa8a9706f2c902e877e616aca51e06f
      
      Patch by andriigrynenko!
      
      Reviewed By: andrewcox
      
      Differential Revision: D3500482
      
      fbshipit-source-id: f51f4bb4ebf0d95a898eb1d4098459aa691acd61
      691cd11c
    • Philip Pronin's avatar
      fix ZSTD support · 151e22b2
      Philip Pronin authored
      Summary:
      Existing logic is broken (unable to correctly handle chained `IOBuf`
      in case of both `compress` and `uncompress`) and has unnecessarly strict
      `needsUncompressedLength() == true` requirement.
      
      This diff switches `ZSTDCodec` to use streaming to handle chained `IOBuf`,
      drops `needsUncompressedLength() == true`.
      
      Reviewed By: luciang
      
      Differential Revision: D3827579
      
      fbshipit-source-id: 0ef6a9ea664ef585d0e181bff6ca17166b28efc2
      151e22b2
  3. 19 Sep, 2016 1 commit
    • Qi Wang's avatar
      Try using the last Deferred reader slot first · 8d329050
      Qi Wang authored
      Summary:
      When trying to find an empty deferred reader slot, getting the current CPU can
      take quite a few cycles, e.g. >1% CPU on SMC (https://fburl.com/434646643).
      
      Let's track the last slot used by this thread and try that slot first before reading
      CPU id and doing the search.
      
      u-benchmark results seem to be improving generally (though a bit noisy and not
      sure how much to trust). Results w/ this diff on left side:
      P56648675
      
      Reviewed By: nbronson
      
      Differential Revision: D3857793
      
      fbshipit-source-id: 8b1c005362c82e748a663100f889b0b99dc257fe
      8d329050
  4. 16 Sep, 2016 6 commits
    • Dominik Gabi's avatar
      move `shellQuote` to implementation file · 5bebf3c9
      Dominik Gabi authored
      Summary: Fixing ODR violations...
      
      Reviewed By: simpkins, yfeldblum
      
      Differential Revision: D3875667
      
      fbshipit-source-id: 0d8ec0b48e14fffb7e3e60c0e68e2576b2f58d1e
      5bebf3c9
    • Dominik Gabi's avatar
      escape `{` in cmd for deprecated `Substring(std::string...)` · d9749c81
      Dominik Gabi authored
      Summary:
      Since `shellify` interprets the command as a format string we need to escape
      `{` and `}`.
      
      Reviewed By: ldemailly, simpkins
      
      Differential Revision: D3874605
      
      fbshipit-source-id: f47db387c3a44a3ba1c0c1d4726b7212fcb5ef3e
      d9749c81
    • Adam Simpkins's avatar
      update stats APIs to use TimePoint vs Duration correctly · 42ca5613
      Adam Simpkins authored
      Summary:
      Update the stats APIs to correcly distinguish between TimePoint and Duration
      types.
      
      This does leave addValue() and update() APIs in place that accept Duration
      values, for backwards compatibility.  These should eventually be removed once
      all code has been converted to call the new APIs.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3808805
      
      fbshipit-source-id: 36d6574ba4a09db7eb9f1a35e47addd3e07f8461
      42ca5613
    • Tom Jackson's avatar
      Return rvalue references from &&-qualified members of dynamic · 864eb2a6
      Tom Jackson authored
      Summary: Let the caller do a move, don't force one.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3873129
      
      fbshipit-source-id: 40c6bf564bcbf794830c99ea1248a9c1bb30e9b0
      864eb2a6
    • Vladimir Slaykovskiy's avatar
      Reduce footprint of ScribeClient · 2adb6eb0
      Vladimir Slaykovskiy authored
      Summary:
      I've found all code paths that contributed to the number of threads in new ScribeClient. Here's a list of flags that reduce the number of thread:
        --default_tls_thread_count=1 # was 32
        --sr2_event_base_pool_size=1
        --has_thrift_dispatcher_reporter=0 # creates a thrift server with a few extra threads
        --observer_manager_pool_size=1 # default is 4
      
      Optimizations in this diff:
      - Don't initialize OBCClient object if it is not used
      - Added FLAG_observer_manager_pool_size to control size of the pool in ObserverManager
      
      Currently OBC counters are switched off globally in ScribeCliean, it means that new code path that creates SR instances is disabled, but eventually we plan to switch it on. Clients that don't use SR and want to keep their RSS/threads profile low, should pass flags listed above. I'll announce this in ScribeUsers group as well.
      
      Differential Revision: D3870704
      
      fbshipit-source-id: 0efad6b3dc43c072ab11cac7e9461c09532ea11c
      2adb6eb0
    • Eric Niebler's avatar
      work around LLVM#30305 in folly::Expected, use unified initialization syntax for extra goodness · a610249b
      Eric Niebler authored
      Summary: The behavior of inheriting constructors changed in clang 3.9 (see https://llvm.org/bugs/show_bug.cgi?id=30305), and folly::Expected needs to change accordingly. As a drive-by improvement, change all invocations of default constructors to use unified initialization syntax.
      
      Reviewed By: igorsugak
      
      Differential Revision: D3872994
      
      fbshipit-source-id: fdaea8b35980df21b8522e2c3d5a8c3be1d84efa
      a610249b
  5. 15 Sep, 2016 7 commits
    • Jim Meyering's avatar
      folly/.../ExceptionTracerLib.cpp: provide less DOF fodder (avoid heap use-after-free) · 101b2ad7
      Jim Meyering authored
      Summary:
      Before this change, an application would fail consistently with a shutdown-time heap use-after-free (i.e., destructor-order-fiasco when one of the following symbols was used after its static-destruction-triggered free):
      
        DECLARE_CALLBACK(CxaThrow);
        DECLARE_CALLBACK(CxaBeginCatch);
        DECLARE_CALLBACK(CxaRethrow);
        DECLARE_CALLBACK(CxaEndCatch);
        DECLARE_CALLBACK(RethrowException);
      
      Each of those would define a classic meyers singleton.
      Since each destructor is trivial, we can fix this by making each a pseudo-leaky (indestructible) meyers singleton instead. Since each static value is never destroyed,
      it can never cause a DOF error again.
      
      Differential Revision: D3870740
      
      fbshipit-source-id: 625f5d5268768ca0e4125bed72bc66c53618be29
      101b2ad7
    • Christopher Dykes's avatar
      Kill unneeded dependency on portability/Memory.h · 6848287d
      Christopher Dykes authored
      Summary: This dependency was added but isn't actually needed, so get rid of it.
      
      Reviewed By: mzlee
      
      Differential Revision: D3863923
      
      fbshipit-source-id: 407d2b3db759e30c37d876dde133fc962daeaeae
      6848287d
    • Neel Goyal's avatar
      Add flag to indicate a session resumption attempt · fd032019
      Neel Goyal authored
      Summary: Track when session resumption was attempted during connect
      
      Reviewed By: shamdor-fb
      
      Differential Revision: D3861028
      
      fbshipit-source-id: 26ca41084faeeb64666b6833896b9510ef2b4c25
      fd032019
    • Adam Simpkins's avatar
      a simple first step towards using clocks properly in the stats code · 8b030a19
      Adam Simpkins authored
      Summary:
      Update the timeseries and histogram classes to accept a clock parameter as a
      template parameter, instead of a time duration type.
      
      This is a first step towards transitioning the code to correctly distinguishing
      between time_point and duration types.  This defines TimePoint and Duration
      type aliases, but does not start using them yet.
      
      In upcoming diffs I will start converting more APIs to correctly use TimePoint
      instead of just Duration.
      
      For now the default clock type is folly::LegacyStatsClock, which still uses
      std::chrono::seconds as the default duration.  At the moment the stats code is
      optimized for second granularity--the addValue() code has a fast path when
      called in the same second as the last update.  When using finer granularity
      durations this fast path can't be used as often.  I will also send out
      subsequent diffs to make the code optimized for updates within the same bucket,
      rather than just updates with the exact same time value.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3807715
      
      fbshipit-source-id: 77696c4f44a8d85e4d6ff84d7656fe7a9709797c
      8b030a19
    • Dominik Gabi's avatar
      ignore `$SHELL` in `shellify` · 9637519e
      Dominik Gabi authored
      Summary:
      Why `$SHELL` is a bad idea:
      
      - getenv() is not thread safe. (In practice it should work if other threads aren't calling setenv(), but still seems undesirable if we can avoid it.)
      - It seems confusing for the program to have different behavior for different developers.
      - Other shells besides /bin/sh may have different quoting behaviors. For instance, I don't think csh allows unescaped newlines inside single quotes.
      - SHELL might be set to other non-shell-like programs in some cases. (Say, if this gets run from inside a git or mercurial hook it might end up being set to the restricted git or hg shell that only lets you run specific commands.)
      Anyway, this isn't related to your diff, so nothing needs to be done for now,
      but I would vote for changing this to always use /bin/sh in a future diff.
      
      Both the C system() call and python's subprocess module appear to
      always use /bin/sh and ignore $SHELL.
      
      Reviewed By: simpkins
      
      Differential Revision: D3867047
      
      fbshipit-source-id: dab0e6afbe1c20ff13d9a52f212df95af425dd77
      9637519e
    • Dominik Gabi's avatar
      formatting support for `Subprocess::shellify` · e69e359c
      Dominik Gabi authored
      Summary:
      Adding formatting support with automatic escaping of parameters. Will
      subsequentyl try and make it harder for people to use non-statically determined
      format strings for this.
      
      Reviewed By: simpkins
      
      Differential Revision: D3866174
      
      fbshipit-source-id: 80bb5886386692643876116fbf338ca0d6986e6a
      e69e359c
    • Dominik Gabi's avatar
      deprecate `folly::Subprocess(std::string, ...)` · 8f27d856
      Dominik Gabi authored
      Summary:
      introducing `Subprocess::shellify` to get around this. Still thinking
      about how to make sure people escape arguments passing into that function. I'd
      like to have something along the lines of Phabricator's `csprintf` here.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3857827
      
      fbshipit-source-id: 8afbc9f1c62c62e0fc91782e11b808145b370933
      8f27d856
  6. 14 Sep, 2016 3 commits
    • Mark Williams's avatar
      Make ElfCache follow .gnu_debuglink · 3272dfdb
      Mark Williams authored
      Summary:
      If you split out debug info into a separate file, folly::Symbolizer
      didn't find it, and failed to include file and line number info in
      backtraces.
      
      This adds a new open mode which follows the .gnu_debuginfo link, and
      uses it from ElfCache and SignalSafeElfCache.
      
      Reviewed By: meyering, luciang
      
      Differential Revision: D3852311
      
      fbshipit-source-id: fec9e57378ae59fa1b82d41a163bb9cfcf9ca23c
      3272dfdb
    • Christopher Dykes's avatar
      Swap a newly added include of gtest.h with portability/GTest.h · 9f838616
      Christopher Dykes authored
      Summary: Because it's needed with the way the portability layer works.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3863954
      
      fbshipit-source-id: 3b682dcc2d2799f17c61fe16a4391fc9f0c2b127
      9f838616
    • Phil Willoughby's avatar
      Test for folly::SingletonThreadLocal · 953890fe
      Phil Willoughby authored
      Summary: Validates that we create a distinct singleton for each thread and that each such singleton is destroyed at its owning-thread's exit.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3849146
      
      fbshipit-source-id: af878b32ecfc6c82b866d7a805e1385d74a8a5f5
      953890fe
  7. 13 Sep, 2016 5 commits
  8. 12 Sep, 2016 1 commit
    • Giuseppe Ottaviano's avatar
      Do not mess with NDEBUG in fbstring · fd01e2bf
      Giuseppe Ottaviano authored
      Summary: Temporarily overriding `NDEBUG` can have unexpected side-effects depending on the implementation of `<assert.h>`. Better use an explicit macro for `assert()` that we can explicitly disable.
      
      Reviewed By: Gownta
      
      Differential Revision: D3850717
      
      fbshipit-source-id: b1e7fce89ab4120b0224e9c6bf668d983b3d2d31
      fd01e2bf
  9. 10 Sep, 2016 3 commits
    • Christopher Dykes's avatar
      Use the GTest portability headers · 6a6ac91e
      Christopher Dykes authored
      Summary:
      Switch all of the uses of `<gtest/gtest.h>` to `<folly/portability/GTest.h>`.
      
      This is painful but necessary to get the tests to compile nicely under MSVC.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3837300
      
      fbshipit-source-id: 7ae43a5d5ba94c8c24fa23a485f18546416e7191
      6a6ac91e
    • Christopher Dykes's avatar
      Use the GMock portability header · 90989a73
      Christopher Dykes authored
      Summary:
      Switch all of the uses of <gmock/gmock.h> to <folly/portability/GMock.h>.
      
      This is painful but necessary to get the tests to compile nicely under MSVC.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3837529
      
      fbshipit-source-id: 7221dfea8f2a880919690b5b0601ca91642991ae
      90989a73
    • Christopher Dykes's avatar
      Add portability headers for GTest and GMock · af5dbcc3
      Christopher Dykes authored
      Summary:
      Both the gtest and gmock headers include `<io.h>` on Windows, which conflicts with how the portability headers include it, so a specific include order is required before either of those headers can be included. As that's brittle and messy, create a pair of portability headers for them instead, so that those can be included instead.
      
      This only adds the headers. The switch to using them will be done in a later pair of diffs.
      
      Reviewed By: mzlee
      
      Differential Revision: D3837221
      
      fbshipit-source-id: 82a273485cdd4536f1153d958c171bfe3ec32e0b
      af5dbcc3
  10. 09 Sep, 2016 5 commits
    • Eric Niebler's avatar
      Refactor basic_fbstring · dbd70eed
      Eric Niebler authored
      Summary: Move fbstring_core and basic_fbstring member functions from in-situ to out-of-class inlines and refactor for readability. Remove superfluous dependence on scope_guard.
      
      Reviewed By: ot, luciang
      
      Differential Revision: D3795250
      
      fbshipit-source-id: f6edca25d4771181faff9e0a4339bbaffd71a370
      dbd70eed
    • Yedidya Feldblum's avatar
      Nomenclature in Synchronized - prefer read to shared · 2e8a121a
      Yedidya Feldblum authored
      Summary:
      [Folly] Nomenclature in `Synchronized` - prefer `read` to `shared`.
      
      `folly::Synchronized` is a higher-level abstraction, so it will use higher-level nomenclature than will lower-level tools like `std::mutex` and `folly::LockTraits`. `shared` describes the lock state, and is used in the C++ libraries. `read` describes the class of operations that calling code is permitted to perform.
      
      Reviewed By: simpkins
      
      Differential Revision: D3840060
      
      fbshipit-source-id: 4b23eaa391cb59d1eca2bfacf72db89d3c7c591e
      2e8a121a
    • Daniel Sommermann's avatar
      Add forwarding gather() function to IOBufQueue · 2f028f63
      Daniel Sommermann authored
      Summary:
      I'm working with a parser that requires a certain number of
      contiguous bytes to be able to make forward progress. I'm also using
      IOBufQueue to receive data from an AsyncReader::ReadCallback with
      pre/postallocate. So, I need to call gather() to ensure that the queue's
      front IOBuf has the right number of contiguous bytes available.
      
      Reviewed By: djwatson
      
      Differential Revision: D3838079
      
      fbshipit-source-id: 9f1ec5c86895eb1b2b109f9f145ca42d2dbba4c6
      2f028f63
    • Anirudh Ramachandran's avatar
      Make folly::PasswordCollector::getPassword const · 0c723a60
      Anirudh Ramachandran authored
      Summary: As in title
      
      Reviewed By: siyengar
      
      Differential Revision: D3794648
      
      fbshipit-source-id: f0b7052f34ecce65cf4e21d546d08c7a6b0a8ee3
      0c723a60
    • Michael Lee's avatar
      #if FOLLY_HAVE_INT128_T rather than #ifdef · 6b3b5def
      Michael Lee authored
      Summary: Switch from #ifdef to #if so the configuration can define the macro to 0
      
      Reviewed By: yfeldblum, Orvid
      
      Differential Revision: D3838748
      
      fbshipit-source-id: e287b07f0fdfdc86c882538e96f2078795b85bfd
      6b3b5def
  11. 08 Sep, 2016 2 commits
    • Denis Samoylov's avatar
      move AsyncSSLSocket logging level for errors to vlog · f4962102
      Denis Samoylov authored
      Summary: current log entries ("E0906 AsyncSSLSocket.cpp:117] TCP connect failed: AsyncSocketException: connect failed, type = Socket not open, errno = 111 (Connection refused)") are not very helpful to debug due lack of details and can spam logs of application that uses async library without ability to disable logging
      
      Reviewed By: djwatson
      
      Differential Revision: D3825048
      
      fbshipit-source-id: 1c97f14e1ea3f1b276d04bb12483d42372a0d186
      f4962102
    • Maged Michael's avatar
      Dynamic expansion of folly MPMC queue · 59ea1768
      Maged Michael authored
      Summary:
      This diff allows queues to start with small capacity and expand as needed up to the specified capacity.
      The main additions and changes:
      - Extra template parameter `Dynamic` that enables dynamic expansion (`default 'false').
      - `ClosedArray` type.
      - Extra members:
        -- `dstate_`: a packed 64 bit unsigned int that contains a seqlock (which implicitly indicates the number of expansions and the lowest ticket for the current `dslots_/dcapacity_/dstride_` configuration.
       -- `dcapacity_`: current dynamic capacity.
       -- `dslots_`: current dynamic slots array. (in anonymous union with `slots_`)
       -- `dstride_`: current dynamic stride. (in anonymous union with `stride_`)
       -- `closed_` a logarithmic-sized array of ClosedArray to hold information about earlier smaller queue arrays for use by lagging consumers.
      
      Design sketch:
      - Reallocate a new larger array on expansion
      - Expansion uses a seqlock. The common case critical path includes a seqlock read-only section.
      - Lagging consumers and lagging blocking producers use a logarithmic-sized array for info about closed arrays
      - Tickets are adjusted by an offset (to accounts for the tickets associated with earlier closed arrays) in order to calculate appropriate index and turn.
      - The synching of `pushTicket_` with the ticket offset packed in `dstate_` is tricky. `pushTicket_` is accessed outside `dstate_`'s seqlock.
      
      Reviewed By: djwatson
      
      Differential Revision: D3462592
      
      fbshipit-source-id: d442a7694190cca3c33753409ffac941d7463f83
      59ea1768