Skip to content

Commit 5edaf7d

Browse files
authored
fix: Catch exceptions that occur when handling octo packets. (#1650)
1 parent 76af4ab commit 5edaf7d

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

jvb/src/main/kotlin/org/jitsi/videobridge/transport/udp/UdpTransport.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import org.jitsi.utils.logging2.Logger
2323
import org.jitsi.utils.logging2.createChildLogger
2424
import org.jitsi.utils.secs
2525
import org.jitsi.utils.stats.RateTracker
26-
import java.io.IOException
2726
import java.net.DatagramPacket
2827
import java.net.DatagramSocket
2928
import java.net.InetAddress
@@ -93,12 +92,21 @@ class UdpTransport @JvmOverloads @Throws(SocketException::class, UnknownHostExce
9392
} catch (sce: SocketException) {
9493
logger.info("Socket closed, stopping reader")
9594
break
96-
} catch (e: IOException) {
95+
} catch (e: Exception) {
9796
logger.warn("Exception while reading ", e)
97+
stats.exceptionOccurred()
98+
continue
9899
}
100+
99101
val now = clock.instant()
100102
stats.packetReceived(packet.length, now)
101-
incomingDataHandler?.dataReceived(buf, packet.offset, packet.length, now) ?: stats.incomingPacketDropped()
103+
try {
104+
incomingDataHandler?.dataReceived(buf, packet.offset, packet.length, now)
105+
?: stats.incomingPacketDropped()
106+
} catch (e: Exception) {
107+
stats.exceptionOccurred()
108+
logger.warn("Exception while handling:", e)
109+
}
102110
}
103111
}
104112

@@ -150,6 +158,7 @@ class UdpTransport @JvmOverloads @Throws(SocketException::class, UnknownHostExce
150158
private val receiveBitRate: BitrateTracker = BitrateTracker(RATE_INTERVAL, RATE_BUCKET_SIZE)
151159
private val sendPacketRate: RateTracker = RateTracker(RATE_INTERVAL, RATE_BUCKET_SIZE)
152160
private val sendBitRate: BitrateTracker = BitrateTracker(RATE_INTERVAL, RATE_BUCKET_SIZE)
161+
private val exceptions = LongAdder()
153162

154163
fun packetReceived(numBytes: Int, time: Instant) {
155164
packetsReceived.increment()
@@ -169,13 +178,9 @@ class UdpTransport @JvmOverloads @Throws(SocketException::class, UnknownHostExce
169178
}
170179
}
171180

172-
fun incomingPacketDropped() {
173-
incomingPacketsDropped.increment()
174-
}
175-
176-
fun outgoingPacketDropped() {
177-
outgoingPacketsDropped.increment()
178-
}
181+
fun incomingPacketDropped() = incomingPacketsDropped.increment()
182+
fun outgoingPacketDropped() = outgoingPacketsDropped.increment()
183+
fun exceptionOccurred() = exceptions.increment()
179184

180185
fun toJson(): OrderedJsonObject = OrderedJsonObject().apply {
181186
put("packets_received", packetsReceived.sum())
@@ -186,6 +191,7 @@ class UdpTransport @JvmOverloads @Throws(SocketException::class, UnknownHostExce
186191
put("send_packet_rate_pps", sendPacketRate.rate)
187192
put("outgoing_packets_dropped", outgoingPacketsDropped.sum())
188193
put("bytes_sent", bytesSent.sum())
194+
put("exceptions", exceptions.sum())
189195
}
190196

191197
fun toSnapshot(): StatsSnapshot = StatsSnapshot(

0 commit comments

Comments
 (0)