【问题标题】:Ingress support for websocket对 websocket 的入口支持
【发布时间】:2020-08-15 20:26:01
【问题描述】:

我有一个在k8s 下运行的jetty Web 应用程序。这个网络应用程序有一个 websocket 端点。部署的服务通过https 上的nginx 入口公开。

一切正常,我的 web 应用程序正在运行,websockets 工作正常(即消息被推送和接收),但 websockets 关闭时出现1006 错误代码,老实说,这并没有阻止我的代码工作但也不好看。

websocket 暴露@/notifications。在“正常”配置中,即不是k8s,只是安装在虚拟机上的普通软件,我需要将以下内容添加到nginx.conf

location /notifications {
   proxy_pass http://XXX/notifications;
   proxy_read_timeout 3700s;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "Upgrade";
   proxy_set_header Origin '';
}

我尝试通过入口这样做

nginx.ingress.kubernetes.io/configuration-sn-p: |

  location /notifications {
    proxy_pass http://webapp:8080/notifications;
    proxy_http_version 1.1;
    proxy_set_header Upgrade "websocket";
    proxy_set_header Connection "Upgrade";
  }

但是没有效果,即我检查了生成的nginx.conf,并没有添加这样的块...

以前有人遇到过这样的问题吗?关于如何解决1006 问题的任何线索?

【问题讨论】:

    标签: nginx kubernetes websocket jetty kubernetes-ingress


    【解决方案1】:

    1006含义

    根据RFC-64551006表示Abnormal Closure

    用于指示连接在预期状态码时异常关闭(即没有发送关闭帧)。

    另见CloseReason.CloseCodes (Java(TM) EE 7 Specification APIs)

    服务器或客户端有很多可能的原因。

    客户端错误:尝试websocket.org Echo Test

    为了隔离和调试客户端的错误,您可以使用websocket.org Echo Test

    关于服务器错误

    码头

    与码头相关的讨论在这里:Question regarding abnormal · Issue #604 · eclipse/jetty.project。但它不包含任何解决方案。

    golang 服务器代码的竞争检测器

    如果你的服务器写在golang,你可以试试Data Race Detector - The Go Programming Language

    数据竞争是并发系统中最常见和最难调试的错误类型之一。当两个 goroutine 同时访问同一个变量并且至少其中一个访问是写入时,就会发生数据竞争。详情请见The Go Memory Model

    以下是可能导致崩溃和内存损坏的数据争用示例:

    func main() {
      c := make(chan bool)
      m := make(map\[string\]string)
      go func() {
          m\["1"\] = "a" // First conflicting access.
          c <- true
      }()
      m\["2"\] = "b" // Second conflicting access.
      <-c
      for k, v := range m {
          fmt.Println(k, v)
      }
    }
    

    PHP 代码案例

    这里讨论的PHP 代码案例:Unclean a closed connection by close() websocket's method (1006) · Issue #236 · walkor/Workerman

    【讨论】:

      猜你喜欢
      • 2019-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-10
      • 2015-08-03
      • 2018-02-02
      相关资源
      最近更新 更多