Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Delay UDP connect until first log event emission #293

Closed
clear1 opened this issue Jan 31, 2023 · 6 comments
Closed

Delay UDP connect until first log event emission #293

clear1 opened this issue Jan 31, 2023 · 6 comments
Labels
type: enhancement A general enhancement
Milestone

Comments

@clear1
Copy link

clear1 commented Jan 31, 2023

v1.15.0
If network is absent and level has value OFF then rise java.net.SocketException: Network is unreachable: connect
(1.14.1 all work fine)

logback.xml:

<appender name="gelf-udp" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
        <host>udp:10.129.106.150</host>
        <port>2514</port>
        <version>1.1</version>
        <originHost>develop</originHost>
        <facility>GELF</facility>
        <extractStackTrace>true</extractStackTrace>
        <filterStackTrace>true</filterStackTrace>
        <includeLocation>true</includeLocation>
        <mdcProfiling>true</mdcProfiling>
        <timestampPattern>yyyy-MM-dd HH:mm:ss,SSS</timestampPattern>
        <maximumMessageSize>2048</maximumMessageSize>
        <includeFullMdc>true</includeFullMdc>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>OFF</level>
        </filter>
    </appender>

Error:

30-01-2023 18:01:12.364 [main] ERROR o.s.boot.SpringApplication.reportFailure - Application run failed
java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected:
ERROR in biz.paluch.logging.gelf.logback.GelfLogbackAppender[gelf-udp] - Network is unreachable: connect java.net.SocketException: Network is unreachable: connect
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:344)
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:344)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.etp.tm.kdh.iop.ServerApplication.main(ServerApplication.java:37)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: java.lang.IllegalStateException: Logback configuration error detected:
@mp911de
Copy link
Owner

mp911de commented Jan 31, 2023

Can you get hold of the stack trace for the SocketException? Generally, log system startup with networked senders requires network connectivity as the sockets are starting early.

@mp911de mp911de added status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Jan 31, 2023
@clear1
Copy link
Author

clear1 commented Jan 31, 2023

If I disable all network adapters then rise exception. But how to get stacktrace?

@mp911de
Copy link
Owner

mp911de commented Jan 31, 2023

The exception is truncated at Caused by: java.lang.IllegalStateException: Logback configuration error detected:. Alternatively, you can set a breakpoint in your debugger in the LoggingApplicationListener class in the initializeSystem method.

@clear1
Copy link
Author

clear1 commented Feb 2, 2023

Hello!
GelfLogbackAppender create instance of GelfUDPSender which is an implementation of GelfSender.
look at method connect () when try to create
DatagramChannel connect = ((DatagramChannel)this.channel()).connect(inetSocketAddress); rised a SocketException which stored in reportError.
Then LogbackLoggingSystem->loadConfiguration method, the statuses of all elements of the logging context are checked, this SocketException is detected and an IllegalStateException is thrown, which crashes the entire application.
Isn't it more logical in this case to turn off the appender, rather than destroy everything?

@mp911de
Copy link
Owner

mp911de commented Feb 2, 2023

Isn't it more logical in this case to turn off the appender, rather than destroy everything?

This is an assumption that varies across projects. Logback has a lifecycle mechanism to start and stop individual appenders. If the orchestrating system would consider these means properly and leave failed appenders as is, then you would not have that kind of issue.

@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Jun 29, 2023
@mp911de mp911de changed the title Error if network is absent Delay UDP connect until first log event emission Jun 29, 2023
@mp911de
Copy link
Owner

mp911de commented Jun 29, 2023

Similar to the TCP sender, we can delay the connect of the UDP sender until receiving the first log event.

@mp911de mp911de added this to the 1.15.1 milestone Jun 29, 2023
@mp911de mp911de closed this as completed Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants