Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*/
package com.netflix.spectator.sidecar;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedByInterruptException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.DatagramChannel;
import java.nio.charset.StandardCharsets;
Expand All @@ -29,8 +27,6 @@
/** Writer that outputs data to UDP socket. */
final class UdpWriter extends SidecarWriter {

private static final Logger LOGGER = LoggerFactory.getLogger(UdpWriter.class);

private final SocketAddress address;
private final ReentrantLock lock;
private volatile DatagramChannel channel;
Expand Down Expand Up @@ -63,6 +59,12 @@ private void connect() throws IOException {
DatagramChannel ch = channel;
try {
ch.write(buffer);
} catch (ClosedByInterruptException e) {
// Thread was interrupted (e.g., Spark task cancellation). Reconnection is futile
// because the thread is still in an interrupted state and any new channel I/O will
// immediately fail. Re-throw to let SidecarWriter suppress repeated warnings.
Thread.currentThread().interrupt();
throw e;
} catch (ClosedChannelException e) {
lock.lock();
try {
Expand All @@ -75,7 +77,6 @@ private void connect() throws IOException {
channel.write(buffer);
// Write succeeded after reconnection
} catch (IOException ex) {
LOGGER.warn("channel closed, failed to reconnect", ex);
ex.initCause(e);
throw ex;
}
Expand All @@ -86,7 +87,6 @@ private void connect() throws IOException {
channel.write(buffer);
// Write succeeded with reconnected channel
} catch (IOException ex) {
LOGGER.warn("failed to write after reconnection by another thread", ex);
ex.initCause(e);
throw ex;
}
Expand Down