mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
Use writeRetry in case of exception during writing to the log
This commit is contained in:
parent
8ec874dc33
commit
3d9218dbfa
@ -11,6 +11,7 @@
|
||||
#include <Common/DNSResolver.h>
|
||||
#include <common/getThreadId.h>
|
||||
#include <Common/SensitiveDataMasker.h>
|
||||
#include <Common/IO.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -43,10 +44,6 @@ void OwnSplitChannel::tryLogSplit(const Poco::Message & msg)
|
||||
{
|
||||
logSplit(msg);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
MemoryTracker::LockExceptionInThread lock_memory_tracker(VariableContext::Global);
|
||||
|
||||
/// It is better to catch the errors here in order to avoid
|
||||
/// breaking some functionality because of unexpected "File not
|
||||
/// found" (or similar) error.
|
||||
@ -57,20 +54,21 @@ void OwnSplitChannel::tryLogSplit(const Poco::Message & msg)
|
||||
/// Also note, that we cannot log the exception here, since this
|
||||
/// will lead to recursion, using regular tryLogCurrentException().
|
||||
/// but let's log it into the stderr at least.
|
||||
std::string message = "Cannot add message to the log:\n";
|
||||
message += msg.getText();
|
||||
message += "\n";
|
||||
message += getCurrentExceptionMessage(true);
|
||||
|
||||
try
|
||||
{
|
||||
WriteBufferFromFileDescriptor out(STDERR_FILENO, 4096);
|
||||
writeBinary(message, out);
|
||||
out.finalize();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
/// Nothing can be done. Ignore the exception.
|
||||
MemoryTracker::LockExceptionInThread lock_memory_tracker(VariableContext::Global);
|
||||
|
||||
const std::string & exception_message = getCurrentExceptionMessage(true);
|
||||
const std::string & message = msg.getText();
|
||||
|
||||
if (!writeRetry(STDERR_FILENO, "Cannot add message to the log: ") ||
|
||||
!writeRetry(STDERR_FILENO, message.data(), message.size()) ||
|
||||
!writeRetry(STDERR_FILENO, "\n") ||
|
||||
!writeRetry(STDERR_FILENO, exception_message.data(), exception_message.size()) ||
|
||||
!writeRetry(STDERR_FILENO, "\n")
|
||||
)
|
||||
{
|
||||
/// Nothing can be done. Ignore the error.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user