普通网友 2019-04-06 00:51
浏览 111
已采纳

无法检测到Kubernetes中的TCP服务没有Golang应用程序的Pod

I have a statsd client that pushes to a kubernetes-hosted statsd service in tcp.

When I redeploy the service and update its pods on the server, the data stops flowing but I have no error on the statsd client.

Based on this thread, I have added a read detection to my golang library to see if I receive a message, but nothing.

I start the connection, send statsd packets from the client, then after I while, I scale the statsd Service down to 0 pods, but the client continues to successfully read and write from the tcp channel without errors!

When I scale the deployment back to 1, the old client does not reconnect and the client and the server continue to remain non-communicating forever.

How can I receive an error from the client when the server replicas go to 0 in the Kubernetes service?

The statsd client is a fork of https://github.com/alexcesaro/statsd

Note that we are aware that statsd is used mostly in UDP but this is a custom flavor and for several reason we need one instance of this in TCP (already have several UDP ones and they don't have this problem)

...
    c.w, err = net.DialTimeout(c.network, c.addr, 5*time.Second)
...

func (c *conn) checkTCPConnectionOpen() error {
    if c.network[:3] == "tcp" {
        one := []byte{}
        _, err := c.w.Read(one)
        return err
    }
    return nil
}

func (c *conn) flush(n int) {
    if len(c.buf) == 0 {
        return
    }
    if n == 0 {
        n = len(c.buf)
    }

    err := c.checkTCPConnectionOpen()
    c.handleError(err)

    _, err = c.w.Write(c.buf[:n])
    c.handleError(err)
    if n < len(c.buf) {
        copy(c.buf, c.buf[n:])
    }
    c.buf = c.buf[:len(c.buf)-n]
}
  • 写回答

2条回答 默认 最新

  • dongye9228 2019-04-10 16:34
    关注

    Ok so this is not a Kubernetes problem, but a golang one.

    This is basically a duplicate of How to know TCP connection is closed in Golang net package?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。