Skip to content

Commit 68f7f56

Browse files
Add AddressSanitizer to DEBUG builds (#1279)
#1276 addressed a `Segementation fault`, but from the error alone, the root cause was not obvious: ``` 31168 Segmentation fault: 11 build/cpp_client ``` By adding [`asan`](https://learn.microsoft.com/en-us/cpp/sanitizers/asan) to the `DEBUG` builds, the CI job would've failed with a much more helpful error message: ``` ================================================================= ==37978==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000040 (pc 0x7eff21446d48 bp 0x7efeff67fce0 sp 0x7efeff67fcd0 T22) ==37978==The signal is caused by a READ memory access. ==37978==Hint: address points to the zero page. #0 0x7eff21446d48 in hazelcast::logger::enabled(hazelcast::logger::level) /home/runner/work/hazelcast-cpp-client/hazelcast-cpp-client/hazelcast/src/hazelcast/logger.cpp:71 #1 0x7eff20a05b1d in hazelcast::client::protocol::codec::client_addclusterviewlistener_handler::handle(hazelcast::client::protocol::ClientMessage&) /home/runner/work/hazelcast-cpp-client/hazelcast-cpp-client/hazelcast/generated-sources/src/hazelcast/client/protocol/codec/codecs.cpp:145 {...} AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV /home/runner/work/hazelcast-cpp-client/hazelcast-cpp-client/hazelcast/src/hazelcast/logger.cpp:71 in hazelcast::logger::enabled(hazelcast::logger::level) ``` --------- Co-authored-by: ihsan demir <[email protected]>
1 parent 200da3d commit 68f7f56

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

.github/actions/build-test/unix/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ runs:
6161
AWS_ACCESS_KEY_ID: ${{ inputs.AWS_ACCESS_KEY_ID }}
6262
AWS_SECRET_ACCESS_KEY: ${{ inputs.AWS_SECRET_ACCESS_KEY }}
6363
HZ_TEST_AWS_INSTANCE_PRIVATE_IP: ${{ inputs.HZ_TEST_AWS_INSTANCE_PRIVATE_IP }}
64+
BUILD_TYPE: ${{ inputs.BUILD_TYPE }}
6465
shell: ${{ env.shell }}
6566
run: |
6667
./scripts/test-unix.sh

.github/actions/coverage-report/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ env:
2222
# Not possible to set this as a default
2323
# https://github.com/orgs/community/discussions/46670
2424
shell: bash
25+
BUILD_TYPE: Debug
2526

2627
runs:
2728
using: composite
@@ -63,7 +64,7 @@ runs:
6364
env:
6465
BUILD_DIR: build
6566
COVERAGE: ON
66-
BUILD_TYPE: Debug
67+
BUILD_TYPE: ${{ env.BUILD_TYPE }}
6768
shell: ${{ env.shell }}
6869
run: |
6970
./scripts/build-unix.sh \
@@ -80,6 +81,7 @@ runs:
8081
AWS_ACCESS_KEY_ID: ${{ inputs.AWS_ACCESS_KEY_ID }}
8182
AWS_SECRET_ACCESS_KEY: ${{ inputs.AWS_SECRET_ACCESS_KEY }}
8283
HZ_TEST_AWS_INSTANCE_PRIVATE_IP: ${{ inputs.HZ_TEST_AWS_INSTANCE_PRIVATE_IP }}
84+
BUILD_TYPE: ${{ env.BUILD_TYPE }}
8385
shell: ${{ env.shell }}
8486
run: |
8587
ulimit -c unlimited

scripts/build-unix.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ CXXFLAGS="$CXXFLAGS -Wall"
3333
if [ "${BUILD_TYPE}" = "Debug" ]; then
3434
# treat compiler warnings as errors when the build type is Debug
3535
CXXFLAGS="$CXXFLAGS -Werror"
36+
# enable address sanitizer to provide meaningful stack traces
37+
CXXFLAGS="$CXXFLAGS -fsanitize=address -fno-omit-frame-pointer"
3638
fi
3739

3840
# remove the given build directory if already exists

scripts/build-windows.bat

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@
1212

1313
@call .\scripts\windows-common.bat
1414

15-
REM print variables for debugging
16-
@echo SOLUTION_TYPE = %SOLUTION_TYPE%
17-
@echo PLATFORM = %PLATFORM%
18-
@echo BUILD_DIR = %BUILD_DIR%
15+
@REM print variables for debugging
16+
@echo SOLUTION_TYPE = %SOLUTION_TYPE%
17+
@echo PLATFORM = %PLATFORM%
18+
@echo BUILD_DIR = %BUILD_DIR%
19+
@echo BUILD_CONFIGURATION = %BUILD_CONFIGURATION%
20+
21+
if "%BUILD_CONFIGURATION%"=="Debug" (
22+
@REM Enable address sanitizer to provide meaningful stack traces
23+
@REM Not enabled due to failure with tooling on GitHub Actions
24+
@REM https://github.com/actions/runner-images/issues/7739
25+
@REM set CXXFLAGS=%CXXFLAGS% -fsanitize=address
26+
)
1927

2028
REM remove the given build directory if already exists
2129
@rd /s /q %BUILD_DIR%

scripts/test-unix.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ else
5454
echo "Server started in $((RC_START_TIMEOUT_IN_SECS - timeout)) seconds"
5555
fi
5656

57+
if [ "${BUILD_TYPE}" = "Debug" ] && [ -z "${ASAN_OPTIONS}" ]; then
58+
# disable leak detection
59+
# need to address outstanding issues before we can aggressively block new ones
60+
# https://github.com/hazelcast/hazelcast-cpp-client/issues/1282
61+
export ASAN_OPTIONS=detect_leaks=0
62+
fi
63+
5764
echo "Starting the client test now."
5865
${TEST_EXECUTABLE} --gtest_output="xml:CPP_Client_Test_Report.xml" &
5966
testPid=$!

scripts/test-windows.bat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ exit /b 1
4646

4747
:server_started
4848

49+
if "%BUILD_CONFIGURATION%"=="Debug" (
50+
if "x%ASAN_OPTIONS%"=="x" (
51+
@REM disable leak detection
52+
@REM need to address outstanding issues before we can aggressively block new ones
53+
@REM https://github.com/hazelcast/hazelcast-cpp-client/issues/1282
54+
set ASAN_OPTIONS=detect_leaks=0
55+
)
56+
)
57+
4958
echo "Starting the client test now."
5059

5160
set PATH=%BUILD_DIR%\%BUILD_CONFIGURATION%;%BUILD_DIR%\bin\%BUILD_CONFIGURATION%;%PATH%

0 commit comments

Comments
 (0)