diff options
author | Arne Juul <arnej@yahoo-inc.com> | 2019-06-13 13:51:51 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahoo-inc.com> | 2019-06-13 13:51:51 +0000 |
commit | 3edcf2ffb75471b548b5eab78748ae9b49f18ad6 (patch) | |
tree | bf837ebac81bd88565e696cd7139ddb5f713e293 /logserver | |
parent | 5d9ac8c747ed3a2ce0106fba72e2a13589303630 (diff) |
avoid race condition that would cause flush() to be called after close()
Diffstat (limited to 'logserver')
-rw-r--r-- | logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriter.java | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriter.java b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriter.java index 47a9b04291d..83d6a4a0def 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriter.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriter.java @@ -46,11 +46,7 @@ public class LogWriter { * </UL> */ private Writer nextWriter() throws IOException { - - if (writer != null) { - writer.close(); - } - + close(); int maxAttempts = 1000; while (maxAttempts-- > 0) { String name = prefix + "-" + generation++; @@ -119,15 +115,15 @@ public class LogWriter { } - public void flush() throws IOException { + public synchronized void flush() throws IOException { if (writer != null) { writer.flush(); } } - public void close() throws IOException { - flush(); + public synchronized void close() throws IOException { if (writer != null) { + writer.flush(); writer.close(); writer = null; } |