Skip to content

Commit

Permalink
folly: async: fix SIOF in test
Browse files Browse the repository at this point in the history
Summary: avoid sillyness:

```
$ _build/opt/folly/io/async/test/async_test --gtest_list_tests
ASAN:SIGSEGV
=================================================================
==3245135==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x000000583444 sp 0x7fff17ba0c40 bp 0x7fff17ba0c80 T0)
    #0 0x583443 in std::_Rb_tree<int, std::pair<int const, folly::SSLContext::SSLLockType>, std::_Select1st<std::pair<int const, folly::SSLContext::SSLLockType> >, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > >::operator=(std::_Rb_tree<int, std::pair<int const, folly::SSLContext::SSLLockType>, std::_Select1st<std::pair<int const, folly::SSLContext::SSLLockType> >, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > > const&) third-party2/libgcc/4.9.x/gcc-4.9-glibc-2.20-fb/024dbc3/include/c++/4.9.x/bits/stl_tree.h:1138
    #1 0x583443 in std::map<int, folly::SSLContext::SSLLockType, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > >::operator=(std::map<int, folly::SSLContext::SSLLockType, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > > const&) third-party2/libgcc/4.9.x/gcc-4.9-glibc-2.20-fb/024dbc3/include/c++/4.9.x/bits/stl_map.h:295
    #2 0x583443 in folly::SSLContext::setSSLLockTypes(std::map<int, folly::SSLContext::SSLLockType, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > >) folly/io/async/SSLContext.cpp:682
    #3 0x40e028 in Initializer folly/io/async/test/AsyncSSLSocketTest2.cpp:143
    #4 0x40e028 in __static_initialization_and_destruction_0 folly/io/async/test/AsyncSSLSocketTest2.cpp:146
    #5 0x40e028 in _GLOBAL__sub_I__ZN5folly47AsyncSSLSocketTest2_AttachDetachSSLContext_Test10test_info_E folly/io/async/test/AsyncSSLSocketTest2.cpp:147
    #6 0x66cf2e in __libc_csu_init /home/engshare/third-party2/glibc/2.20/src/glibc-2.20/csu/elf-init.c:88
    #7 0x7f7145600084 in __libc_start_main (/usr/local/fbcode/gcc-4.9-glibc-2.20-fb/lib/libc.so.6+0x20084)
    #8 0x410be5 (/data/users/lucian/fbcode2/_build/opt/folly/io/async/test/async_test+0x410be5)

AddressSanitizer can not provide additional info.
AAAAAAASUMMARY: AddressSanitizer: SEGV third-party2/libgcc/4.9.x/gcc-4.9-glibc-2.20-fb/024dbc3/include/c++/4.9.x/bits/stl_tree.h:1138 std::_Rb_tree<int, std::pair<int const, folly::SSLContext::SSLLockType>, std::_Select1st<std::pair<int const, folly::SSLContext::SSLLockType> >, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > >::operator=(std::_Rb_tree<int, std::pair<int const, folly::SSLContext::SSLLockType>, std::_Select1st<std::pair<int const, folly::SSLContext::SSLLockType> >, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > > const&)
==3245135==ABORTING
```

Reviewed By: @philippv

Differential Revision: D2440796
  • Loading branch information
luciang authored and facebook-github-bot-9 committed Sep 15, 2015
1 parent 2b179f9 commit 062f90e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
1 change: 1 addition & 0 deletions folly/gen/test/FileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ INSTANTIATE_TEST_CASE_P(
DifferentBufferSizes,
FileGenBufferedTest,
::testing::Values(0, 1, 2, 4, 8, 64, 4096));

int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);
Expand Down
8 changes: 2 additions & 6 deletions folly/io/async/SSLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,17 +626,13 @@ struct SSLLock {
// SSLContext runs in such environments.
// Instead of declaring a static member we "new" the static
// member so that it won't be destructed on exit().
static std::map<int, SSLContext::SSLLockType>* lockTypesInst =
new std::map<int, SSLContext::SSLLockType>();

static std::unique_ptr<SSLLock[]>* locksInst =
new std::unique_ptr<SSLLock[]>();

static std::unique_ptr<SSLLock[]>& locks() {
static auto locksInst = new std::unique_ptr<SSLLock[]>();
return *locksInst;
}

static std::map<int, SSLContext::SSLLockType>& lockTypes() {
static auto lockTypesInst = new std::map<int, SSLContext::SSLLockType>();
return *lockTypesInst;
}

Expand Down
29 changes: 12 additions & 17 deletions folly/io/async/test/AsyncSSLSocketTest2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <folly/io/async/AsyncSSLSocket.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/SSLContext.h>

using std::string;
using std::vector;
Expand Down Expand Up @@ -127,21 +128,15 @@ TEST(AsyncSSLSocketTest2, AttachDetachSSLContext) {
eventBase.loop();
}

} // folly

int main(int argc, char *argv[]) {
signal(SIGPIPE, SIG_IGN);
folly::SSLContext::setSSLLockTypes({
{CRYPTO_LOCK_EVP_PKEY, folly::SSLContext::LOCK_NONE},
{CRYPTO_LOCK_SSL_SESSION, folly::SSLContext::LOCK_SPINLOCK},
{CRYPTO_LOCK_SSL_CTX, folly::SSLContext::LOCK_NONE}});
testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);
return RUN_ALL_TESTS();
}
///////////////////////////////////////////////////////////////////////////
// init_unit_test_suite
///////////////////////////////////////////////////////////////////////////

namespace {
using folly::SSLContext;
struct Initializer {
Initializer() {
signal(SIGPIPE, SIG_IGN);
SSLContext::setSSLLockTypes({
{CRYPTO_LOCK_EVP_PKEY, SSLContext::LOCK_NONE},
{CRYPTO_LOCK_SSL_SESSION, SSLContext::LOCK_SPINLOCK},
{CRYPTO_LOCK_SSL_CTX, SSLContext::LOCK_NONE}});
}
};
Initializer initializer;
} // anonymous

0 comments on commit 062f90e

Please sign in to comment.