|
17 | 17 | package org.apache.logging.log4j.jdbc.appender;
|
18 | 18 |
|
19 | 19 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
| 20 | +import java.io.Reader; |
20 | 21 | import java.io.StringReader;
|
21 | 22 | import java.sql.Clob;
|
22 | 23 | import java.sql.Connection;
|
@@ -833,7 +834,10 @@ private Object truncate(final String nameKey, Object value) {
|
833 | 834 |
|
834 | 835 | @Override
|
835 | 836 | protected void writeInternal(final LogEvent event) {
|
836 |
| - StringReader reader = null; |
| 837 | + // Don't close StringReaders because of (1) batching, (2) resources are not allocated, and (3) they'll be GC'd |
| 838 | + // away. |
| 839 | + // See https://github.com/apache/logging-log4j2/issues/3127 where closing StringReaders too soon can cause |
| 840 | + // problems. |
837 | 841 | try {
|
838 | 842 | if (!this.isRunning() || isClosed(this.connection) || isClosed(this.statement)) {
|
839 | 843 | throw new AppenderLoggingException(
|
@@ -879,7 +883,7 @@ protected void writeInternal(final LogEvent event) {
|
879 | 883 | if (column.isEventTimestamp()) {
|
880 | 884 | this.statement.setTimestamp(j++, new Timestamp(event.getTimeMillis()));
|
881 | 885 | } else if (column.isClob()) {
|
882 |
| - reader = new StringReader(column.getLayout().toSerializable(event)); |
| 886 | + final Reader reader = new StringReader(column.getLayout().toSerializable(event)); |
883 | 887 | if (column.isUnicode()) {
|
884 | 888 | this.statement.setNClob(j++, reader);
|
885 | 889 | } else {
|
@@ -929,7 +933,6 @@ protected void writeInternal(final LogEvent event) {
|
929 | 933 | } catch (final SQLException e) {
|
930 | 934 | // Ignore
|
931 | 935 | }
|
932 |
| - Closer.closeSilently(reader); |
933 | 936 | }
|
934 | 937 | }
|
935 | 938 |
|
|
0 commit comments