add HTTP2Codec to DownstreamSessionTests

Summary: Get some additional HTTP/2 coverage, also added SPDY/3.1 to the typed tests.

Test Plan: Ran the tests

Reviewed By: praveenr@fb.com

Subscribers: hannesr, doug, bmatheny

FB internal diff: D1728139

Signature: t1:1728139:1418434633:c1068ab2e019e445c8df5e43f9123d204c06f36a
Move TAsyncTransport to folly as AsyncTransportWrapper

Summary:
This temporary class will be useful to cut dependencies on thrift
while (roughly) maintaining the old interface.

Fixup various test classes that depend on the interface.  Next diff will be to cut fbthrift dep in proxygen/mcrouter

Test Plan: unit tests, jenkins

Reviewed By: hans@fb.com

Subscribers: fbcode-common-diffs@, andrewcox, alandau, bmatheny, alikhtarov, mshneer, trunkagent, doug, njormrod, folly-diffs@, davejwatson

FB internal diff: D1696094

Signature: t1:1696094:1418762312:6028815cce2845ac5f8e754132a038fabf5fd957
TraceEventObserver refactor

Summary:
All right, this is the TraceEventObserver refactor diff that all of us are excited about.
The design discussion happened a week ago in the group post: https://www.facebook.com/groups/csti.developers/permalink/765817406800210/
Major things that I did in this diff:
- Change TraceEventContext into containing a vector of TraceEventObservers;
- Create java interface for TraceEventObserver and TraceEventContext; Per result of the discussion in the post, events are batched in cpp and only passed back to java when a request finishes.
- Remove RequestStat from ResponseHandler interface and turned it into a TEO;
- Implemented java version of RequestStats;
- Kill ProxygenLogFilter and turned it into a TEO; Ideally we should directly turn CircularLogSink into a TEO but this diff is already too big.
- Cleanup along the way;

Note that I temporarily disabled the trace events in RetryFilter and RedirectFilter. The data is not urgently needed for now and we should treat it differently in the new model. Other than that, all the functionality should remain the same as it is today.

I also need to cleanup RequestStats all the clients in fbcode who use our httpclient and ResponseHandler. But otherwise it should be good to receive review. My apology in advance for the diff size but it is hard to split this out as it involve some interface change. But actually it is less horrible than the number of lines it shows.

Test Plan: Fix all the tests and added the RequestStatsTest in java.

Reviewed By: subodh@fb.com

Subscribers: abirchall, trunkagent, ps, bmatheny, seanc

FB internal diff: D1692041

Tasks: 5285227

Signature: t1:1692041:1419028717:50dbc8e4d42e50700caac0050157151c3fc1a343
Fix build

Summary: D1692041 broke the build

Test Plan: OSS contbuild

Reviewed By: seanc@fb.com

Subscribers: bmatheny

FB internal diff: D1753885

Tasks: 5877718

Signature: t1:1753885:1419273905:c69110d8017d2c695f8513aa494494de2c6a76fd
Move MockTimeoutManager from thrift to proxygen

Summary:
Only proxygen is using it, but maybe folly would be better?

Facebook:
^

Test Plan: Unit tests

Reviewed By: davejwatson@fb.com

Subscribers: noamler, doug, alandau, bmatheny, mshneer

FB internal diff: D1746748

Tasks: 5816910

Signature: t1:1746748:1419027440:090c7820433ba72a21e081be8af09a1b8814aee6
Rewrite AsyncTimeoutSet tests with MockTimeoutClock

Summary: The AsyncTimeoutSetTests are flaky, especially on systems running ntpdate, because the system clock can change wildly and mess up the tolerances.  Instead, make time a virtual interface for AsyncTimeoutSet, and explicitly move the clock one millisecond at a time to test the desired behavior.

Test Plan: Ran the tests

Reviewed By: ajitb@fb.com

Subscribers: doug, bmatheny

FB internal diff: D1746763

Tasks: 5816910

Signature: t1:1746763:1418859430:d109ea0d17367e471b656f71642108978d4cad88
Never close the socket while there are outstanding txns

Summary:
When HTTPTransaction is destroyed it invokes the handler's detachTransaction method.  The transaction has access to some socket structures which need to be valid in case the handler is using them.  The code that invoked closeWithReset() was not taking into account that some transactions may still be on the current call-stack, with CallbackGuards holding them open.  As the stack unwinds, the last txn will detach itself and the socket will cleanup in checkForShutdown.

Test Plan: Unit tests, will canary and canary with ASAN

Reviewed By: viswanath@fb.com

Subscribers: doug, bmatheny

FB internal diff: D1751679

Tasks: 5865651

Signature: t1:1751679:1419055313:af5b6f87baba89d900e1c64062aa36c0247b34ac
Don't FATAL on bad frame

Summary:
If we are expecting a CONTINUATION frame, don't FATAL printing out the type of the unknown frame.

Facebook:
This seems to happen in latest.  Not sure if our bug or chrome bug

Test Plan: New unit test

Reviewed By: viswanath@fb.com

Subscribers: doug, bmatheny

FB internal diff: D1753988

Signature: t1:1753988:1419274422:3f1fa408d35e29d57a785e7283d7e4afcfcb3184
Rework egress flow control

Summary:
Make egress flow control for HTTPSession work more like ingress flow control.  Decouple the 'socket is full, don't write' state from 'HTTPSession has too much buffered data, ask HTTPTransactions/Handlers to stop sending' state.

This commits more user space memory to buffering.  Previously, as soon as the kernel socket buffer was full, we would immediately egress pause all txns/handlers.  Now they can continue to call send* methods until the total amount of egress data buffered for this socket in user-space exceeds pendingWriteMax.

This should increase the amount of data that can be egressed per loop for sessions with < 8 transactions.  Previously HTTPTransaction would automatically pause its handler when it had 8kb buffered.  Now it will rely on the session to invoke the pause at 64k (by default).  Hopefully matching the ingress and egress buffering logic will reduce latency for proxies.

There's still one failing unit test that is relying on the old behavior of HTTPSession, but it's pretty complicated.  I'll fix it.

Test Plan: Unit tests

Reviewed By: brianp@fb.com

Subscribers: trunkagent, doug, bmatheny

FB internal diff: D1707808

Signature: t1:1707808:1417563256:e1ce8883fbbb19f2f40525b03e7ca51212737ca5
fix clang build breakage

Summary: ^

Test Plan: compiled.  What a concept.

Reviewed By: woo@fb.com

Subscribers: doug, bmatheny, mathieubaudet

FB internal diff: D1756489

Signature: t1:1756489:1419369051:87194d17f843b3f71f5aa1dda85a2e141fe07b1a
Fix broken test

Summary: Oddly, this only broke for OSS.  The onEgressPaused/Resumed callbacks were never being invoked, which gtest should have flagged as an error.  I added a Seequence to force the problem, and re-ordered the callbacks

Test Plan: Unit tests

Reviewed By: woo@fb.com

Subscribers: doug, bmatheny

FB internal diff: D1756953

Signature: t1:1756953:1419380722:044446d5eedc07c9ce9183fec8b5beb570099f77
Fix livelock on SessionPool while creating a txn on a closing session

Summary:
Expose isClosing() in HTTPUpstreamSession to check if socket is closing
or session is draining.

Facebook:
HTTPSession::createTransaction() refuses to create a txn if socket is
shutdown/shutting down, but SessionPool bypasses this check, attempts to
create...a txn and refuses to drain the session. If
SessionPool::getNumActiveNonFullSession() == 1, this would enter a
livelock.

This changes SessionPool to check if the session is closing (socket is
closing/closed, session is draining, etc) and drain the session
accordingly.

Test Plan:
Added a unit test. Without the fix in SessionHolder::isPoolable, the
unit test enters a livelock within attemptOpenTransaction.
Will canary.

Reviewed By: afrind@fb.com

Subscribers: bmatheny

FB internal diff: D1756686

Tasks: 5858603

Signature: t1:1756686:1419383736:0d96a59f8cb9149f652560ca93d557c8563b060b
Revert "[proxygen] Rework egress flow control"

Summary:
This reverts commit 4d816b9ab9e5b77cb3b6798b18a5fd78cb54e61b.

Facebook: jenkins builds have been failing - I have not been able to debug
root cause and am taking out the revert hammer.

Test Plan: Copied over code to a ubuntu box in EC2, ran the tests

Reviewed By: woo@fb.com

Subscribers: bmatheny, afrind

FB internal diff: D1757911

Signature: t1:1757911:1419621649:c9e9ee347f16a34688a28c975ee9287d39c2f88a
Really wait until we're in the event loop

Summary:
The barrier is released too early; if the caller
calls runInEventBaseLoop or does various other things
too soon after WorkerThread::start() returns, bad things
could happen (but probably won't).

Test Plan:
Inspection. waitUntilRunning() has fixed a couple
of subtle, only-under-high-load (with the wind blowing in the
right direction) bugs.

Reviewed By: davejwatson@fb.com

Subscribers: bmatheny

FB internal diff: D1750366

Signature: t1:1750366:1419012798:35321db083d992378dcab16e7dbf969a49fe2482
Bump version to 10:0