|
17 | 17 | package org.apache.logging.log4j.core.appender.db.jdbc;
|
18 | 18 |
|
19 | 19 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
| 20 | +import java.io.Reader; |
20 | 21 | import java.io.Serializable;
|
21 | 22 | import java.io.StringReader;
|
22 | 23 | import java.sql.Clob;
|
@@ -945,7 +946,10 @@ private Object truncate(final String nameKey, Object value) {
|
945 | 946 |
|
946 | 947 | @Override
|
947 | 948 | protected void writeInternal(final LogEvent event, final Serializable serializable) {
|
948 |
| - StringReader reader = null; |
| 949 | + // Don't close StringReaders because of (1) batching, (2) resources are not allocated, and (3) they'll be GC'd |
| 950 | + // away. |
| 951 | + // See https://github.com/apache/logging-log4j2/issues/3127 where closing StringReaders too soon can cause |
| 952 | + // problems. |
949 | 953 | try {
|
950 | 954 | if (!this.isRunning() || isClosed(this.connection) || isClosed(this.statement)) {
|
951 | 955 | throw new AppenderLoggingException(
|
@@ -990,7 +994,7 @@ protected void writeInternal(final LogEvent event, final Serializable serializab
|
990 | 994 | if (column.isEventTimestamp()) {
|
991 | 995 | this.statement.setTimestamp(j++, new Timestamp(event.getTimeMillis()));
|
992 | 996 | } else if (column.isClob()) {
|
993 |
| - reader = new StringReader(column.getLayout().toSerializable(event)); |
| 997 | + final Reader reader = new StringReader(column.getLayout().toSerializable(event)); |
994 | 998 | if (column.isUnicode()) {
|
995 | 999 | this.statement.setNClob(j++, reader);
|
996 | 1000 | } else {
|
@@ -1040,7 +1044,6 @@ protected void writeInternal(final LogEvent event, final Serializable serializab
|
1040 | 1044 | } catch (final SQLException e) {
|
1041 | 1045 | // Ignore
|
1042 | 1046 | }
|
1043 |
| - Closer.closeSilently(reader); |
1044 | 1047 | }
|
1045 | 1048 | }
|
1046 | 1049 |
|
|
0 commit comments