I am troubleshooting a simple polling application crash that seems to be random, but there's a few select areas that it crashes. One of them is this function here:
Logger::Log is a static function, as follows:
The Mutex is static.
This is a multithreaded application. Is there any issues with the above function being called multiple times at once? I can't see why, but maybe I'm missing something? Note that the Logger::Log() function also gets called directly. It always crashes at the first function though. The crash is "Broken pipe".
I can post the entire code if needed, but as a start, just wondering if there's anything I'm doing wrong in this particular function.
Code:
void ShardListEntry::Debug(string str)
{
Logger::Log("{" + m_sname + "} : " + str); //line 62 of ShardListEntry.cpp
}
Logger::Log is a static function, as follows:
Code:
void Logger::Log(string entry)
{
loggermutex.Lock();
rslib::DateTime tmpdate = rslib::DateTime::Now();
string filename="log/poller" + logfilenum + "-" + tmpdate.GetDate("l") + ".log";
string logentry = "[" + tmpdate.GetDate() + "] " + entry + "\n";
fstream fout(filename.c_str(),ios::app | ios::out);
fout<<logentry<<"\n";
fout.close(); //line 23 of logger.cpp
if(consoleoutput)cout<<logentry<<endl;
loggermutex.UnLock();
}
The Mutex is static.
This is a multithreaded application. Is there any issues with the above function being called multiple times at once? I can't see why, but maybe I'm missing something? Note that the Logger::Log() function also gets called directly. It always crashes at the first function though. The crash is "Broken pipe".
Code:
Program received signal SIGPIPE, Broken pipe.
[Switching to Thread 0x4f112950 (LWP 10582)]
0x0000003a7580db0b in write () from /lib64/libpthread.so.0
Current language: auto; currently asm
Missing separate debuginfos, use: debuginfo-install keyutils.x86_64
(gdb) backtrace
#0 0x0000003a7580db0b in write () from /lib64/libpthread.so.0
#1 0x0000003c1d6c1ca6 in xwrite (__fd=<value optimized out>, __s=<value optimized out>, __n=<value optimized out>) at basic_file.cc:126
#2 0x0000003c1d66d3ac in std::basic_filebuf<char, std::char_traits<char> >::_M_convert_to_external (this=<value optimized out>,
__ibuf=<value optimized out>, __ilen=<value optimized out>)
at /usr/src/debug/gcc-4.3.0-20080428/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/fstream.tcc:504
#3 0x0000003c1d66d4f6 in std::basic_filebuf<char, std::char_traits<char> >::overflow (this=<value optimized out>, __c=<value optimized out>)
at /usr/src/debug/gcc-4.3.0-20080428/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/fstream.tcc:431
#4 0x0000003c1d66de96 in std::basic_filebuf<char, std::char_traits<char> >::_M_terminate_output (this=<value optimized out>)
at /usr/src/debug/gcc-4.3.0-20080428/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/fstream.tcc:786
#5 0x0000003c1d66e1c8 in std::basic_filebuf<char, std::char_traits<char> >::close (this=<value optimized out>)
at /usr/src/debug/gcc-4.3.0-20080428/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/fstream.tcc:159
#6 0x0000003c1d66f69d in std::basic_fstream<char, std::char_traits<char> >::close (this=<value optimized out>)
at /usr/src/debug/gcc-4.3.0-20080428/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/fstream:775
#7 0x0000000000421a6b in Logger::Log (entry=
{static npos = 18446744073709551615, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x4f111b10 "\ufffd\ufffd\a\ufffd\ufffd\177"}}) at includes/logger.cpp:23
#8 0x00000000004221c3 in ShardListEntry::Debug (this=0x7fcab80240c0, str=
{static npos = 18446744073709551615, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x4f111ed0 "X\ufffd\a\ufffd\ufffd\177"}}) at includes/ShardListEntry.cpp:62
#9 0x000000000042d743 in ShardListEntry::Poll (this=0x7fcab80240c0) at includes/ShardListEntry.cpp:165
#10 0x000000000042e345 in PollThread (data=0x0) at includes/PollThread.cpp:20
#11 0x0000003a7580729a in start_thread (arg=<value optimized out>) at pthread_create.c:297
#12 0x0000003a74ce439d in clone () from /lib64/libc.so.6
(gdb)
I can post the entire code if needed, but as a start, just wondering if there's anything I'm doing wrong in this particular function.
Last edited:
