fluent / fluent/fluent-logger-java

Initial UnknownHostException is Unrecoverable

未关闭
#62 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Java
星标
210
派生
86
PR 合并指标
30 天内没有已合并 PR

描述

The `RawSocketSender` takes a host and port in its constructor and coverts these into an `InetSocketAddress`, which tries to resolve the hostname. On `RawSocketSender` connect this `InetSocketAddress` is used to reconnect, but if it wasn't resolved during fluent-logger init then it will fail over and over. The code snipped from `RawSocketSender` is below:

``` java
public RawSocketSender(String host, int port, int timeout, int bufferCapacity, Reconnector reconnector) {
msgpack = new MessagePack();
msgpack.register(Event.class, Event.EventTemplate.INSTANCE);
pendings = ByteBuffer.allocate(bufferCapacity);
server = new InetSocketAddress(host, port); // Create InetSocketAddress on init
this.reconnector = reconnector;
name = String.format("%s_%d_%d_%d", host, port, timeout, bufferCapacity);
this.timeout = timeout;
}

private void connect() throws IOException {
try {
socket = new Socket();
socket.connect(server, timeout); // Reconnection uses pre-resolved server field
out = new BufferedOutputStream(socket.getOutputStream());
} catch (IOException e) {
throw e;
}
}
```

This issue comes up when using the fluent-logger in a highly dynamic environment (like on Docker Swarm) where apps may come up before a DNS entry in Consul is even resolvable. It also means that during failover of a Fluent host (triggering a DNS change) the then failing socket connection will always try the old Fluent host IP and never re-resolve the DNS entry.

My recommendation is to store the Fluent host and port as private fields within the `RawSocketSender`, not a resolved `InetSocketAddress` (now stored as `this.server`) and create a new `InetSocketAddress` on every socket connection.

I understand there will be performance implications of this and am happy to submit a PR, but wanted to bring it up in an issue in case there were reasons for implementing the `RawSocketSender` the current way.

贡献指南

这个仓库没有索引到贡献指南

调研方向

从 RawSocketSender 构造函数及其 connect() 方法开始,重点查看服务器地址的存储和复用方式。验证初始主机名解析失败时的行为,以及故障转移期间 DNS 发生变化时的行为;当重新连接使用当前的主机名解析结果,而不是旧的已解析地址时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
networking
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。