hazelcast / hazelcast/hazelcast-cpp-client

Default log handler doesn't work when a global hazelcast_client instance is used [API-2364]

Open
#932 1 comment 0 reactions 0 assignees View on GitHub
to-jira Type: Defect
Dominant language
C++
Stars
91
Forks
54
Avg merge
1d 12m
Merged PRs (30d)
5

Description

The default log handler uses a [static local mutex ](https://github.com/hazelcast/hazelcast-cpp-client/blob/12aa0dc6f9a6ef0b376053ad54171d2eaaa6ce95/hazelcast/src/hazelcast/logger.cpp#L99)for synchronizing access to `std::cout`. If a global `hazelcast_client` instance is used in user code and the shutdown() method isn't called before `main()` ends, the dtor of hazelcast_client will implicitly call shutdown and try to print logs during the process. As the order in which the mutex and hazelcast_client be destroyed is not guaranteed, the client may end up accessing an already destroyed mutex.

To reproduce:
```c++
std::vector clis;

int main() {
clis.push_back( hazelcast::new_client().get() );
}
```

The exception thrown from std::mutex::lock will cause the program to abort during termination on macOS.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.