<p>I have a <code>jetty</code> web app running under <code>k8s</code>. This web app has a websocket end point. The service deployed is exposed via an <code>nginx</code> ingress on <code>https</code>.</p>

<p>Everything works fine, I have the web app running and the websockets work fine (ie messages get pushed and received) but the websockets close with a <code>1006</code> error code, which to be honest doesn't stop my code from working but doesn't look good either.</p>

<p>The websocket is exposed @ <code>/notifications</code>. In a "normal" config, ie not <code>k8s</code>, just plain software installed on a VM, I would need to add the following to <code>nginx.conf</code></p>

<pre><code>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 '';
}
</code></pre>

<p>I tried doing this via the ingress</p>

<p>nginx.ingress.kubernetes.io/configuration-snippet: |</p>

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

<p>But it has no effect, ie I checked the <code>nginx.conf</code> generated and there is no such block added...</p>

<p>Anybody has had issues like this before? any clue on how to solve the <code>1006</code> issue?</p>

Thomas
<h2><code>1006</code> meaning</h2>
<p>As per <a href="https://www.rfc-editor.org/rfc/rfc6455#page-46" rel="nofollow noreferrer">RFC-6455</a> <code>1006</code> means <a href="https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes" rel="nofollow noreferrer"><code>Abnormal Closure</code></a>:</p>
<blockquote>
<p>Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected.</p>
</blockquote>
<p>Also see <a href="https://docs.oracle.com/javaee/7/api/javax/websocket/CloseReason.CloseCodes.html#CLOSED_ABNORMALLY" rel="nofollow noreferrer">CloseReason.CloseCodes (Java(TM) EE 7 Specification APIs)</a></p>
<p>There are so many possible causes either on server or on client.</p>
<h2>Client errors: try <a href="https://www.websocket.org/echo.html" rel="nofollow noreferrer">websocket.org <code>Echo Test</code></a></h2>
<p>To isolate and debug client's errors, you may use <a href="https://www.websocket.org/echo.html" rel="nofollow noreferrer">websocket.org Echo Test</a></p>
<h2>As for server error</h2>
<h3>Jetty</h3>
<p>Jetty-related discussion is here: <a href="https://github.com/eclipse/jetty.project/issues/604" rel="nofollow noreferrer">Question regarding abnormal · Issue #604 · eclipse/jetty.project</a>. But it doesn't contain any solutions.</p>
<h3>Race detector for <code>golang</code> server code</h3>
<p>If your server is written on <code>golang</code>, you may try <a href="https://golang.org/doc/articles/race_detector.html" rel="nofollow noreferrer">Data Race Detector - The Go Programming Language</a></p>
<blockquote>
<p>Data races are among the most common and hardest to debug types of bugs in concurrent systems. A data race occurs when two goroutines access the same variable concurrently and at least one of the accesses is a write. See the <a href="https://golang.org/ref/mem/" rel="nofollow noreferrer">The Go Memory Model</a> for details.</p>
<p>Here is an example of a data race that can lead to crashes and memory corruption:</p>
<pre><code>func main() {
  c := make(chan bool)
  m := make(map\[string\]string)
  go func() {
      m\[&quot;1&quot;\] = &quot;a&quot; // First conflicting access.
      c &amp;lt;- true
  }()
  m\[&quot;2&quot;\] = &quot;b&quot; // Second conflicting access.
  &amp;lt;-c
  for k, v := range m {
      fmt.Println(k, v)
  }
}
</code></pre>
</blockquote>
<h3>Case for <code>PHP</code> code</h3>
<p>The case for <code>PHP</code> code discussed here: <a href="https://github.com/walkor/Workerman/issues/236" rel="nofollow noreferrer">Unclean a closed connection by close() websocket's method (1006) · Issue #236 · walkor/Workerman</a></p>
