You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Marc Segond (Jira)" <ji...@apache.org> on 2021/08/22 17:17:00 UTC

[jira] [Comment Edited] (LOG4J2-3140) Mongo4 appender stays in TimeOut

    [ https://issues.apache.org/jira/browse/LOG4J2-3140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17402839#comment-17402839 ] 

Marc Segond edited comment on LOG4J2-3140 at 8/22/21, 5:16 PM:
---------------------------------------------------------------

Sure. Here it is:
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
 <Appenders>
 <Console name="ConsoleAppender" target="SYSTEM_OUT">
 <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
 </Console>
 <File name="FileAppender" fileName="application-${date:yyyyMMdd}.log" immediateFlush="false" append="true">
 <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
 </File>
 <NoSql name="Mongo4">
 <MongoDb4
 capped="true" collectionSize="104857600"
 connection="mongodb+srv://username:password@MyAtlasProject.ne6as.mongodb.net/MyDB.Logs?retryWrites=true&amp;w=majority"
 />
 </NoSql>
 </Appenders>
 <Loggers>
 <Root level="debug">
 <AppenderRef ref="ConsoleAppender"/>
 <!--<AppenderRef ref="FileAppender"/>-->
 <AppenderRef ref="Mongo4"/>
 </Root>
 </Loggers>
</Configuration>{code}
And this is the Exception:
{code:java}
2021-08-22 19:13:23,913 main DEBUG Gettting collection 'Logs'...2021-08-22 19:13:23,913 main DEBUG Gettting collection 'Logs'...2021-08-22 19:13:23,913 main DEBUG Got collection com.mongodb.client.internal.MongoCollectionImpl@10c626be2021-08-22 19:13:23,913 cluster-ClusterId{value='61228595ecd21f5a68a6da9e', description='null'}-srv-testmsds.ne6as.mongodb.net ERROR Unable to write to database [noSqlManager{ description=Mongo4, bufferSize=0, provider=MongoDb4Provider [connectionString=mongodb+srv://username:password@MyAtlasProject.ne6as.mongodb.net/MyDB.Logs?retryWrites=true&w=majority, collectionSize=104857600, isCapped=true, mongoClient=com.mongodb.client.internal.MongoClientImpl@6d07a63d, mongoDatabase=com.mongodb.client.internal.MongoDatabaseImpl@3561c410] }] for appender [Mongo4]. org.apache.logging.log4j.core.appender.AppenderLoggingException: Failed to write log event to MongoDB due to error: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[] at org.apache.logging.log4j.mongodb4.MongoDb4Connection.insertObject(MongoDb4Connection.java:100) at org.apache.logging.log4j.core.appender.nosql.NoSqlDatabaseManager.writeInternal(NoSqlDatabaseManager.java:83) at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.writeThrough(AbstractDatabaseManager.java:291) at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.write(AbstractDatabaseManager.java:264) at org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.append(AbstractDatabaseAppender.java:110) at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156) at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129) at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120) at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84) at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:540) at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:498) at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:481) at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:456) at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:82) at org.apache.logging.log4j.core.Logger.log(Logger.java:161) at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2205) at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2159) at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2142) at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2022) at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1875) at org.apache.logging.slf4j.Log4jLogger.info(Log4jLogger.java:179) at com.mongodb.diagnostics.logging.SLF4JLogger.info(SLF4JLogger.java:71) at com.mongodb.internal.connection.AbstractMultiServerCluster.addServer(AbstractMultiServerCluster.java:349) at com.mongodb.internal.connection.AbstractMultiServerCluster.initialize(AbstractMultiServerCluster.java:98) at com.mongodb.internal.connection.DnsMultiServerCluster$1.initialize(DnsMultiServerCluster.java:47) at com.mongodb.internal.connection.DefaultDnsSrvRecordMonitor$DnsSrvRecordMonitorRunnable.run(DefaultDnsSrvRecordMonitor.java:86) at java.base/java.lang.Thread.run(Thread.java:830)Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[] at com.mongodb.internal.connection.BaseCluster.getDescription(BaseCluster.java:177) at com.mongodb.internal.connection.AbstractMultiServerCluster.getDescription(AbstractMultiServerCluster.java:50) at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:137) at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:94) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:276) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:200) at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:1006) at com.mongodb.client.internal.MongoCollectionImpl.executeInsertOne(MongoCollectionImpl.java:467) at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:450) at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:444) at org.apache.logging.log4j.mongodb4.MongoDb4Connection.insertObject(MongoDb4Connection.java:97) ... 26 more{code}


was (Author: gnumarco):
Sure. Here it is:
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
 <Appenders>
 <Console name="ConsoleAppender" target="SYSTEM_OUT">
 <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
 </Console>
 <File name="FileAppender" fileName="application-${date:yyyyMMdd}.log" immediateFlush="false" append="true">
 <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
 </File>
 <NoSql name="Mongo4">
 <MongoDb4
 capped="true" collectionSize="104857600"
 connection="mongodb+srv://username:password@MyAtlasProject.ne6as.mongodb.net/MyDB.Logs?retryWrites=true&amp;w=majority"
 />
 </NoSql>
 </Appenders>
 <Loggers>
 <Root level="debug">
 <AppenderRef ref="ConsoleAppender"/>
 <!--<AppenderRef ref="FileAppender"/>-->
 <AppenderRef ref="Mongo4"/>
 </Root>
 </Loggers>
</Configuration>{code}

> Mongo4 appender stays in TimeOut
> --------------------------------
>
>                 Key: LOG4J2-3140
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3140
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.14.1
>         Environment: OpenJDK 11 and 13, Windows 10, IntelliJ, MongoDB 4.4.8, mongo-driver-sync 4.3.1.
>            Reporter: Marc Segond
>            Priority: Major
>              Labels: MongoDB, log4j2, mongodb4
>
> I have configured a Mongo4 Appender for logging into my MongoDB Atlas Cluster.
> I have the mongo-driver-sync 4.3.1 in my pom.xml, and I use a connection string of type:
> |mongodb+srv://<username>:<password>@myproject.ne6as.mongodb.net/myFirstDatabase?retryWrites=true&w=majority|
> When my app tries to log, the mongodb connection keeps stalling in the 30000ms timeout waiting for the cluster description.
> The strange thing is that my app does other things with this very same MongoDB, so I have coded a MongoDBService class that handles the connection etc...and my code works perfectly using the same driver and the same connection string: no "waiting for cluster description"...



--
This message was sent by Atlassian Jira
(v8.3.4#803005)