[
https://issues.apache.org/jira/browse/TS-4072?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15240082#comment-15240082
]
ASF GitHub Bot commented on TS-4072:
------------------------------------
Github user jpeach commented on a diff in the pull request:
https://github.com/apache/trafficserver/pull/568#discussion_r59631832
--- Diff: lib/ts/Diags.cc ---
@@ -816,29 +820,39 @@ Diags::set_stdout_output(const char *_bind_stdout)
if (strcmp(_bind_stdout, "") == 0)
return false;
- if (stdout_log) {
- delete stdout_log;
- stdout_log = NULL;
- }
-
- // create backing BaseLogFile for stdout
- stdout_log = new BaseLogFile(_bind_stdout);
+ BaseLogFile *old_stdout_log = stdout_log;
+ BaseLogFile *new_stdout_log = new BaseLogFile(_bind_stdout);
// on any errors we quit
- if (!stdout_log || stdout_log->open_file() !=
BaseLogFile::LOG_FILE_NO_ERROR) {
+ if (!new_stdout_log || new_stdout_log->open_file() !=
BaseLogFile::LOG_FILE_NO_ERROR) {
fprintf(stderr, "[Warning]: unable to open file=%s to bind stdout
to\n", _bind_stdout);
- delete stdout_log;
+ fprintf(stderr, "[Warning]: stdout is currently not bound to
anything\n");
+ delete new_stdout_log;
+ lock();
stdout_log = NULL;
+ unlock();
return false;
}
- if (!stdout_log->m_fp) {
+ if (!new_stdout_log->m_fp) {
fprintf(stderr, "[Warning]: file pointer for stdout %s = NULL\n",
_bind_stdout);
- delete stdout_log;
+ fprintf(stderr, "[Warning]: stdout is currently not bound to
anything\n");
+ delete new_stdout_log;
+ lock();
stdout_log = NULL;
+ unlock();
return false;
}
- return rebind_stdout(fileno(stdout_log->m_fp));
+ // now exchange the stdout_log pointer
+ lock();
+ stdout_log = new_stdout_log;
+ bool ret = rebind_stdout(fileno(new_stdout_log->m_fp));
--- End diff --
If this fails, are we in a well-defined state? No caller ever checks the
return value of this ... what would happen if it fails?
> Diagnostic log rolling races
> ----------------------------
>
> Key: TS-4072
> URL: https://issues.apache.org/jira/browse/TS-4072
> Project: Traffic Server
> Issue Type: Bug
> Components: Logging
> Reporter: James Peach
> Assignee: Daniel Xu
> Fix For: 6.2.0
>
>
> When diagnostic logs are rolled, {{Diags::diags_log}} is deleted and replaced
> with a new log object. Since the global {{diags}} points to a a single
> {{Diags}} object there is nothing to prevent a different thread logging
> through this object at the time it is deleted.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)