Catch logging exception in Scheduler::run

Several Stash crash dumps show that the attempt to log
a message on an exception in Scheduler::run() can cause an
unhandled exception.  This is because logging attempts to
show the current fiber, calling Fiber::getThis(). It seems that
in some cases that is pointing to a Fiber object that has already
been deleted, or maybe with a race condition on another thread
that is calling Fiber::getThis() to allocate a new Fiber.

Unfortunately I don't know how to reproduce this or other info
about the root cause.  And I'm not certain whether this would just
delay the crash to another point in the code rather than really
improving reliability. But it might permit the code to proceed
to a place where a better crash dump would be produced.

refs #98680

Change-Id: I1b89fdc59cdc42ff158d232b94957151ebbd1c89
Signed-off-by: Andrew Skowronski <andrews@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/53647
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Kevin Cai <kevinc@mozy.com>
Reviewed-by: Russ Simons <russs@mozy.com>
fix ServletDispatcher typo in getServlet

* the typo will cause coredump when no serlvet hit.
* refer to ticket #105448

Change-Id: Id65078495a287b2c8854f7bb941f8110725276f9
Signed-off-by: Kevin Cai <kevinc@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/53858
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Eric Wang <leiw@mozy.com>
fix out-of-source build of run_tests

Change-Id: I42db268545dd44fb56dc6a89f6940e0d28f66ffb
Signed-off-by: Kefu Chai <chaik@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/53926
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Andrew Skowronski <andrews@mozy.com>
Reviewed-by: Kevin Cai <kevinc@mozy.com>
fix json bool value handling issue

* under gcc -O2 compiling, bool value will be considered as integer
  directly, the specialization version is not visible
* fix build script, don't export CXXFLAG if is empty, otherwise, it will
  override configure default -O2 compiling

Change-Id: Ib552ec29fc4dde3fe77b1aec4ce9bb6be3b70314
Signed-off-by: Kevin Cai <kevinc@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/54414
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Andrew Skowronski <andrews@mozy.com>
remove operator< for AsyncEvent as it is not used

Change-Id: I927d5dada73298ee23b64dfa11f70487f1189a44
Signed-off-by: Kefu Chai <chaik@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/55064
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Kevin Cai <kevinc@mozy.com>
closes #103108: fix the SSL_read error

* NOTE: Check ticket #95808 for detailed info of this change

* Protect the use of SSL handle m_ssl by m_mutex when calling SSL_*
  functions over it in different fibers. According to the FAQ of
  OpenSSL official site: OpenSSL is thread-safe, but with limitations
  that an SSL connection may not concurrently be used by multiple
  threads.

* Clear ssl error in current thread before calling SSL_* functions on
  SSL handle to avoid error corruptions in different fibers of same thread

* Only try to read and process error if ssl api return code is non-positive.

Change-Id: I5191a73ddb6e195a5efa725506aafc7fe1db7bdd
Signed-off-by: Bert Yuan <berty@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/54988
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Andrew Skowronski <andrews@mozy.com>
Reviewed-by: Kevin Cai <kevinc@mozy.com>
Reviewed-by: Kefu Chai <chaik@mozy.com>
refs #105516, fix UnixAddess in Socket

 * Mordor::Socket::localAddress() fails to set m_localAddress if m_family is
   AF_UNIX so create an UnixAddress in this case
 * the same applies to Mordor::Socket::remoteAddress()

Change-Id: I86fc0d0e368d74a3b3052613854196c55ac41552
Signed-off-by: Kefu Chai <chaik@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/55391
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Kevin Cai <kevinc@mozy.com>
fix FTBFS where boost::mutex is not declared

* also add a virtual dtor for ClientRequest::RequestLogger

Change-Id: If67b0c2c3f4594cb337e64760a092d65dcc53d0c
Signed-off-by: Kefu Chai <chaik@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/55533
Reviewed-by: Andrew Skowronski <andrews@mozy.com>
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
refs #101757: Re-factor memory BIO operations

* Use official way(BIO_read, BIO_write) to operate memory BIO rather
  than the non-well-documented way for reducing ambiguity and better
  code readbility.

Change-Id: I65264ca1a4a552e2e4811871df8394da1fb8ca0b
Signed-off-by: Bert Yuan <berty@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/55462
Reviewed-by: Kefu Chai <chaik@mozy.com>
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Eric Wang <leiw@mozy.com>
Reviewed-by: Andrew Skowronski <andrews@mozy.com>
Reviewed-by: Kevin Cai <Kevin.Cai@mozy.com>
add autoStart param to IOManager ctor

* add autoStart param to IOManager constructor so that derived class can
  do start() properly
* reason: if any class is derived from IOManager and overrides the
  idle() interface, call start() in IOManager contructor will yield an
  incorrect vtable, and hence wrong idle() function for IdleFiber

Change-Id: Id84e5d9da609b1354b31e99379daa5adfb35a924
Signed-off-by: Kevin Cai <kevinc@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/55753
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Andrew Skowronski <andrews@mozy.com>
Reviewed-by: Bert Yuan <berty@mozy.com>
tiny optimization: schedule expired timers when necessary

* don't try to schedule if got empty expired timers

Change-Id: Ia0c873baf4884bf1a717381dbba18811ae429dbb
Signed-off-by: Kevin Cai <kevinc@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/55738
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Kefu Chai <chaik@mozy.com>
Reviewed-by: Kevin Cai <Kevin.Cai@mozy.com>
refs #107767: case insenstive comparsion of "chunked" transferEncoding

Change-Id: I16dfe68956691ed9a4a34d6c5962ea7864999160
Signed-off-by: Kevin Cai <kevinc@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/55866
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Bert Yuan <berty@mozy.com>
Reviewed-by: Eric Wang <leiw@mozy.com>
Reviewed-by: Andrew Skowronski <andrews@mozy.com>
fix pipeStream dead lock

* pipeStream implementation with the sequence:
  1. scoped_lock to lock the mutex
  2. weak_ptr::lock to acquire the shared_ptr
* these two variables will be destroyed in reverse order
  - release the shared_ptr
  - unlock the mutext
* under a race condition that the shared_ptr holds the last reference of
  the instance, ~PipeStream will be invoked while destroying the
  shared_ptr under the mutex. However in ~PipeStream(), it will try to
  acquire the mutex again, which causes a recursively-acquiring-mutex
  deadlock
* fix it by switch the two variables definition order. so that the mutex
  will be unlocked first, and then the pipeStream shared_ptr under no
  lock

Change-Id: I8b6c4bbbe13a12ff05bf06a14cd843f0e04b94a6
Signed-off-by: Kevin Cai <kevinc@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/55924
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Kefu Chai <chaik@mozy.com>
Reviewed-by: Eric Wang <leiw@mozy.com>
Reviewed-by: Andrew Skowronski <andrews@mozy.com>
closes #104209: do not destruct dg in scheduler

* remove the Fiber::reset() method
* remove the negative test case for scheduling a Fiber with unreachable tid
* remove the ASSERTs in schedule()s as they are in header file now, and i dont
  want to pollute header files with the test related code.

Change-Id: Ib8071bc92068cd41671c2161ad8118a7317d733c
Signed-off-by: Kefu Chai <chaik@mozy.com>
Reviewed-on: https://gerrit.dechocorp.com/53927
Reviewed-by: Jenkins <hudsonbuild@mozy.com>
Reviewed-by: Kevin Cai <kevinc@mozy.com>