You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Stefan Jipa (Jira)" <lo...@logging.apache.org> on 2022/05/12 10:32:00 UTC
[jira] [Updated] (LOGCXX-554) Child thread does not inherit a copy of the mapped diagnostic context of its parent
[ https://issues.apache.org/jira/browse/LOGCXX-554?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stefan Jipa updated LOGCXX-554:
-------------------------------
Description:
Hi,
The API documentation for MDC says "The MDC is managed on a per thread basis. A child thread automatically inherits a copy of the mapped diagnostic context of its parent."
However this does not appear to be the case. Take the following testcase:
#include <iostream>
#include <pthread.h>
#include <log4cxx/mdc.h>
using namespace std;
void *threadfunc(void *arg)
{
std::cout << "child: " << log4cxx::MDC::get("mykey") << std::endl;
}
int main(int argc, char *argv[])
{
pthread_t thread_id;
log4cxx::MDC::put("mykey", "123");
std::cout << "main: " << log4cxx::MDC::get("mykey") << std::endl;
pthread_create(&thread_id, NULL, threadfunc, NULL);
pthread_join(thread_id, NULL);
return 0;
}
The resulted output is:
main: 123
child:
Instead of:
main: 123
child: 123
This simple program was executed on red hat 8.3 (used c++17 and log4cxx 0.12.1)
For compiling this simple program I used the following command line:
g++ -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0 -I log4cxx_path/include -L log4cxx_path/lib/ -llog4cxx -L apr-util_path/lib/ -laprutil-1 -L apr_path/lib/ -lapr-1 -pthread -o test_mdc test_mdc.cpp
This issue also happens on windows 64 bit in our applications (log4cxx 0.12.1) and I have found the same issue reported under this jira: LOGCXX-339 (and also is known on web as a latent problem)
I checked the release notes of log4cxx 0.13.0 and it does not seem to address this issue and probably it was never fixed cause the resolution for the issue stated above was supposed to be fixed in the new versions.
Could you check this on the latest log4cxx (0.13.0)? and if is still happening please provide a solution.
Thanks,
Stefan Jipa
was:
Hi,
The API documentation for MDC says "The MDC is managed on a per thread basis. A child thread automatically inherits a copy of the mapped diagnostic context of its parent."
However this does not appear to be the case. Take the following testcase:
#include <iostream>
#include <pthread.h>
#include <log4cxx/mdc.h>
using namespace std;
void *threadfunc(void *arg)
{
std::cout << "child: " << log4cxx::MDC::get("mykey") << std::endl;
}
int main(int argc, char *argv[])
{
pthread_t thread_id;
log4cxx::MDC::put("mykey", "123");
std::cout << "main: " << log4cxx::MDC::get("mykey") << std::endl;
pthread_create(&thread_id, NULL, threadfunc, NULL);
pthread_join(thread_id, NULL);
return 0;
}
The resulted output is:
main: 123
child:
Instead of:
main: 123
child: 123
This simple program was executed on red hat 8.3 (used c++17 and log4cxx 0.12.1)
For compiling this simple program I used the following command line:
g++ -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0 -I log4cxx_path/include -L log4cxx_path/lib/ -llog4cxx -L apr-util_path/lib/ -laprutil-1 -L apr_path/lib/ -lapr-1 -pthread -o test_mdc test_mdc.cpp
This issue also happens on windows 64 bit in our applications (log4cxx 0.12.1) and I have found the same issue reported under this jira: LOGCXX-339 (and also is known on web as a latent problem)
I checked the release notes of log4cxx 0.13.0 and it does not seem to address this issue and probably it was never fixed cause the resolution for the issue stated above was supposed to be fixed in the new versions.
Could you check this on the latest log4cxx (0.13.0) and it is still happening please provide a solution.
Thanks,
Stefan Jipa
> Child thread does not inherit a copy of the mapped diagnostic context of its parent
> -----------------------------------------------------------------------------------
>
> Key: LOGCXX-554
> URL: https://issues.apache.org/jira/browse/LOGCXX-554
> Project: Log4cxx
> Issue Type: Bug
> Affects Versions: 0.12.1, 0.13.0
> Environment: Linux - red hat 8.3/Windows 10/ Windows server 2016 64 bit
> Reporter: Stefan Jipa
> Priority: Major
> Fix For: 0.12.1, 0.13.0
>
>
> Hi,
>
> The API documentation for MDC says "The MDC is managed on a per thread basis. A child thread automatically inherits a copy of the mapped diagnostic context of its parent."
> However this does not appear to be the case. Take the following testcase:
> #include <iostream>
> #include <pthread.h>
> #include <log4cxx/mdc.h>
> using namespace std;
> void *threadfunc(void *arg)
> {
> std::cout << "child: " << log4cxx::MDC::get("mykey") << std::endl;
> }
> int main(int argc, char *argv[])
> {
> pthread_t thread_id;
> log4cxx::MDC::put("mykey", "123");
> std::cout << "main: " << log4cxx::MDC::get("mykey") << std::endl;
> pthread_create(&thread_id, NULL, threadfunc, NULL);
> pthread_join(thread_id, NULL);
> return 0;
> }
>
> The resulted output is:
> main: 123
> child:
>
> Instead of:
> main: 123
> child: 123
>
> This simple program was executed on red hat 8.3 (used c++17 and log4cxx 0.12.1)
> For compiling this simple program I used the following command line:
> g++ -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0 -I log4cxx_path/include -L log4cxx_path/lib/ -llog4cxx -L apr-util_path/lib/ -laprutil-1 -L apr_path/lib/ -lapr-1 -pthread -o test_mdc test_mdc.cpp
> This issue also happens on windows 64 bit in our applications (log4cxx 0.12.1) and I have found the same issue reported under this jira: LOGCXX-339 (and also is known on web as a latent problem)
> I checked the release notes of log4cxx 0.13.0 and it does not seem to address this issue and probably it was never fixed cause the resolution for the issue stated above was supposed to be fixed in the new versions.
>
> Could you check this on the latest log4cxx (0.13.0)? and if is still happening please provide a solution.
>
> Thanks,
> Stefan Jipa
--
This message was sent by Atlassian Jira
(v8.20.7#820007)