Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Spring Boot and handle SSE broken pipe #537

Merged
merged 6 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ val exposedVersion = "0.45.0"
val h2Version = "2.3.232"
val pamGeographyVersion = "2.9"
val tokenValidationVersion = "1.3.0"
val tokenSupportVersion = "4.1.7"
val tokenSupportVersion = "5.0.11"
val oidcSupportVersion = "0.2.18"
val logstashVersion = "8.0"
val pdfboxVersion = "3.0.3"
Expand Down Expand Up @@ -34,7 +34,7 @@ repositories {
plugins {
val kotlinVersion = "2.0.21"
id("org.jetbrains.kotlin.jvm") version kotlinVersion
id("org.springframework.boot") version "3.2.5"
id("org.springframework.boot") version "3.3.5"
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
kotlin("plugin.jpa") version kotlinVersion
idea
Expand All @@ -59,6 +59,7 @@ dependencies {

implementation("org.flywaydb:flyway-core")
implementation("com.zaxxer:HikariCP")
implementation("org.flywaydb:flyway-database-postgresql")
implementation("org.postgresql:postgresql")

implementation("io.github.resilience4j:resilience4j-retry:$resilience4jVersion")
Expand Down
50 changes: 50 additions & 0 deletions src/main/kotlin/no/nav/klage/config/SseBrokenPipeLogFilter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package no.nav.klage.config

import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.turbo.TurboFilter
import ch.qos.logback.core.spi.FilterReply
import no.nav.klage.util.getLogger
import org.slf4j.Marker

class SseBrokenPipeLogFilter : TurboFilter() {

companion object {
@Suppress("JAVA_CLASS_ON_COMPANION")
private val ourLogger = getLogger(javaClass.enclosingClass)
}

override fun decide(
marker: Marker?,
logger: Logger?,
level: Level?,
format: String?,
params: Array<out Any>?,
throwable: Throwable?
): FilterReply {
if (throwable != null) {
if (
(throwable.javaClass.name == "java.io.IOException" &&
throwable.message == "Broken pipe" &&
logger?.name?.contains("org.apache.catalina.core.ContainerBase") == true
)
/*
||
(throwable.javaClass.name == "AsyncRequestNotUsableException" &&
throwable.message?.contains("Broken pipe", ignoreCase = true) == true
)
*/
) {
ourLogger.debug("Suppressing error log message when broken pipe and logger is ${logger.name}. This is probably due to lost client during async/SSE operations.")
return FilterReply.DENY
}
}

if (level == Level.WARN && logger?.name == "org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver" && format?.contains("java.io.IOException: Broken pipe") == true) {
ourLogger.debug("Suppressing warning log message when broken pipe and logger is ${logger.name}. This is probably due to lost client during async/SSE operations.")
return FilterReply.DENY
}

return FilterReply.NEUTRAL
}
}
2 changes: 2 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>

<turboFilter class="no.nav.klage.config.SseBrokenPipeLogFilter" />

<springProfile name="local">
<appender name="text" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
Expand Down