Make Cpp2RequestContext's getHeader protected so server code cannot use it mistakenly.

Summary:
getHeader returns a THeader pointer which is not thread safe.
To get the per-request read headers getHeaders should be used.

Test Plan:
fbconfig thrift/lib/cpp2/test && fbmake runtests
There are probably callsites in fbcode, I'll check for it.

Reviewed By: davejwatson@fb.com

Subscribers: zeus-diffs@, trunkagent, ruibalp, alandau, bmatheny, rbhoj

FB internal diff: D1584918
move shutdownsocketset out of asncoscket

Summary:
Moving async socket to folly, this is the only dep not in folly.  Not convinced this *needs* to be in async socket, as opposed to just the thrift server - it doesn't appear to be used anywhere except in unicorn thrift server.

It ends up being less code this way too.

Test Plan:
fbconfig -r thrift; fbmake runtests

The unittest for this don't look amazing, maybe I should write another

Reviewed By: alandau@fb.com

Subscribers: zeus-diffs@, tw-eng@, benj, scuba-diffs@, trunkagent, doug, rodrigos, alandau, bmatheny, acampi, dcsommer

FB internal diff: D1583629
pass in the right addr length in thrift/UDP/recvfrom

Summary: Before, the length (addrLen) is computed from struct sockaddr,  which is less than sizeof(sockaddr_storage).  While dealing with ipv6 addrs, sockaddr only can save the first several bytes.  That is why we see some random numbers in ipv6 addrs https://phabricator.fb.com/P16519615.  More interesting, we send our gangplank healthcheck responses to the random IPv6 addrs, lol

Test Plan:
manually make some healthcheck requests:  echo health | nc -vu6 slb091.09.frc1 33000

or from shiv-health-inspector,  shiv-health-inspector --host star6-shv-09-frc1.facebook.com --vip udp-priming-star6-shv-09-frc1

UDP 2a03:2880:2110:9f02:face:b00c:0:1:33000 UP    2401:db00:2110:9102:face:0:1:0 Enabled
UDP 2a03:2880:2110:9f02:face:b00c:0:1:33000 UP    2401:db00:2110:9103:face:0:1:0 Enabled

Reviewed By: afrind@fb.com, dcsommer@fb.com

Subscribers: trunkagent, alandau, bmatheny, ljyang, kafai

FB internal diff: D1588395

Tasks: 5191161, 5264399
Fix fatal when using oop option

Summary: There was a mismatch between IThriftStruct and TBase which caused a fatal in generated code. This adds the missing typehints to fix the fatal

Test Plan: Generate code with oop option, attempt to load it in hhvm

Reviewed By: alandau@fb.com

Subscribers: trunkagent, alandau, bmatheny

FB internal diff: D1589235

Tasks: 5226644
Replace some uses of concurrency::Mutex with concurrency::ProfiledMutex<std::mutex>

Summary:
I'll do more later across all of thrift if this goes well. I'm
also curious if I should add a typedef for this later. As in
`concurrency::Mutex` == `concurrency::ProfiledMutex<std::mutex>` and
`concurrency::Guard` == `std::lock_guard<concurrency::ProfiledMutex<std::mutex>>` and

Test Plan: contbuild, unit tests

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, doug, fbcode-common-diffs@, alandau, bmatheny, seanc, pgriess

FB internal diff: D1581203
revert shutdownsocketset

Summary: Revert of D1583629

Test Plan:  none

Waited almost an hour for some sandcastle results.  ANY sandcastle results.  I give up

Reviewed By: ckwalsh@fb.com, haijunz@fb.com

Subscribers: ckwalsh, zeus-diffs@, rodrigos, tw-eng@, benj, acampi, scuba-diffs@, doug, alandau, bmatheny

FB internal diff: D1589839
Stop setting KRB5_CONFIG

Summary: This was a local hack.  Remove it from the open source code.

Test Plan: run tests

Reviewed By: andrei.bajenov@fb.com

Subscribers: trunkagent, alandau, bmatheny

FB internal diff: D1585548

Tasks: 5245246
Fix broken build in service router

Summary: This is caused by D1584918

Test Plan: fbmake

Reviewed By: mshneer@fb.com

Subscribers: trunkagent, mcduff, marccelani, hitesh, mshneer, alandau, bmatheny

FB internal diff: D1590029

Tasks: 5283340
Remove python3 flag

Summary: python3 flag is deprecated and 2/3 compatible code is generated now. This caused some confusion so better just delete it. Also fix a bug that readFromJson uses long to convert a string to an integer.

Test Plan: fbconfig thrift/test/py && fbmake runtests. Also @jsalomon is using it.

Reviewed By: jsalomon@fb.com

Subscribers: trunkagent, jsalomon, alandau

FB internal diff: D1593310
Fix recursive struct's thrift_spec in Python.

Summary:
The problem here is all struct defs are executed but
thrift_spec can be None. This diff makes struct's type spec a mutable
list than recursively fix all None-valued thrift_specs.

Test Plan:
I haven't tested it thoroughly, but it seems fixed the issue
in t5287907 where a struct contains a field of another struct defined
after it.

Reviewed By: alandau@fb.com

Subscribers: trunkagent, ruibalp, alandau, bmatheny

FB internal diff: D1595500

Tasks: 5287907
Revert "Fix recursive struct's thrift_spec in Python."

Summary: This reverts commit fe631f4c2a0a984fc661112fba742dd2fb4e4dae.

Test Plan: it's a revert

Reviewed By: alandau@fb.com

Subscribers: ruibalp, alandau, bmatheny

FB internal diff: D1600028

Tasks: 5324641
move TEventBaseManager to folly/io/async/EventBaseManager

Summary:
This class isn't thrift specific anymore, especially now that TEventBase->EventBase.
Specific use case in folly: folly/experimental/wangle/concurrent/IOThreadPoolExecutor
EventBaseManager itself needs some work/cleanup, but that is for a later diff
For instance, we might try to push towards only allowing access to the singleton, and towards
removing overrides. i.e. only getEventBase. But that's pending an audit of how people are using it now.

Note that the ProfiledMutex protecting the event base set has been made a regular std::mutex

Test Plan:
compiled thrift/lib/cpp|cpp2, made a pass at fixing forward declarations elsewhere
will let contbuild help me iterate

Reviewed By: hans@fb.com

Subscribers: trunkagent, nli, fbcode-common-diffs@, davejwatson, hero-diffs@, zeus-diffs@, andrewcox, netego-diffs@, alandau, apollo-diffs@, antonl, laser-diffs@, ads-dsp-eng@, darshan, micha, njormrod, panin, hdoshi, scuba-diffs@, bmatheny

FB internal diff: D1590827

Tasks: 5247981
Fix security tests after D1585548

Summary:
Set KRB5_CONFIG to /etc/krb5-thrift.conf so the code can find
the correct keytab.

Test Plan: fbmake runtests

Reviewed By: mhorowitz@fb.com

Subscribers: alandau, bmatheny

FB internal diff: D1607012

Tasks: 5343081

Blame Revision: D1585548
Create an abstract base for TMemoryBuffer.

Summary: This allow to reuse the TMemoryBuffer as a base for other transport implementation.

Test Plan: unittests block still passes.

Reviewed By: alandau@fb.com

Subscribers: alandau, bmatheny

FB internal diff: D1607200
Update thrift compact protocol for D

Summary: As per title. It is failing right now when used against up to date server, as server will use version 2 of the protocol.

Test Plan: Connection a thrift server using the compact protocol.

Reviewed By: alandau@fb.com

Subscribers: alandau, bmatheny

FB internal diff: D1607185
forward HandlerCallbackBase properly

Summary: We are missing out ewp when forwarding callbacks

Test Plan: fbconfig -r thrift/lib/cpp && fbmake opt

Reviewed By: philipp@fb.com

Subscribers: trunkagent, alandau, bmatheny

FB internal diff: D1607757
Set thread stack size in NumaThreadFactory

Summary:
Sigma moved to NumaThreadManager in D1467956, and at that time we ignored a setting we had to increase the thread stack size from 1MB to 4MB. We came across an instance in production where we are running out of 1MB of stack space on a thread.
This diff threads some things through various abstractions to allow for users to set the stack size. I may be bulldozing through some abstractions, so please let me know if there's a preferred way to do this.

Test Plan:
fbconfig -r thrift/lib/cpp thrift/lib/cpp2 sigma/service && fbmake opt && fbmake runtests_opt
Run Sigma case that was previously segfaulting (due to stack overflow) and see it pass with flying colors.

Reviewed By: alandau@fb.com

Subscribers: jcoens, ldbrandy, alandau, bmatheny

FB internal diff: D1605621

Tasks: 5137234
Revert "[Thrift] Set thread stack size in NumaThreadFactory"

Summary: This reverts commit 89ca9b1fd9e09596153d41965f495a2df036ecea.

Test Plan: testinprodsev

Reviewed By: mikeelkin2@fb.com

Subscribers: jcoens, ldbrandy, alandau, bmatheny

FB internal diff: D1608325
rm clang as a host-specific option

Summary:
This precludes us from building folly -r with clang, since it includes
a binary that is both a tool and a regular binary. This is a general problem,
and the clang fix was a hack. It is possible that the clang hack fix is still
necessary, but it is about a year old, so we should verify that assertion.

Test Plan:
fbconfig tools/build/test/tests && fbmake runtests
phabricator unit tests

Reviewed By: robbert@fb.com

Subscribers: alandau, trunkagent, simpkins, agallagher, ldbrandy, sdwilsh, mathieubaudet, mpawlowski

FB internal diff: D1601468

Tasks: 5324999
crash fixer: catch all exceptions where TSocketAddress throws system_error

Summary:
There are only two places actually, one in proxygen one in thrift.

This workaround would presumably fix the top1 crash on fbios right now where
TSocketAddress::setFromSocket() throws system_error but "catch
(std::exception&)" won't catch. The diff isn't a big deal for proxygen or
thrift, but could help fbios a lot.

The reason why catch std::exception doesn't work is mysterious. Peter said it's
an exception visibility issue but I am not sure how to fix that.

Test Plan: Tested in xcode, set a breakpoint, wait for a while, resume, didn't see setFromSocket throw anymore. Played a bit while longer, nothing happened.

Reviewed By: pgriess@fb.com

Subscribers: adamjernst, alandau, bmatheny, mshneer, subodh, benyluo, ranjeeth, seanc

FB internal diff: D1609285

Tasks: 5302778