<p dir="auto">This is a regression from v1.32.3 to v1.32.4, likely caused by <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1653574308" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/18587" data-hovercard-type="pull_request" data-hovercard-url="/denoland/deno/pull/18587/hovercard" href="https://github.com/denoland/deno/pull/18587">#18587</a></p>
<p dir="auto">Seems similar to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1527601143" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/17332" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/17332/hovercard" href="https://github.com/denoland/deno/issues/17332">#17332</a>, but given that this is a regression, I thought it warranted a separate issue.</p>
<p dir="auto">See also <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1653574308" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/18587" data-hovercard-type="pull_request" data-hovercard-url="/denoland/deno/pull/18587/hovercard?comment_id=1510189302&amp;comment_type=issue_comment" href="https://github.com/denoland/deno/pull/18587#issuecomment-1510189302">#18587 (comment)</a></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { delay } from &quot;https://deno.land/std@0.183.0/async/mod.ts&quot;
import { serve } from &quot;https://deno.land/std@0.183.0/http/mod.ts&quot;

console.log(Deno.version.deno)

const controller = new AbortController()

serve(async (request) =&gt; {
  const { response, socket } = Deno.upgradeWebSocket(request)

  socket.addEventListener(&quot;open&quot;, async () =&gt; {
    console.log(&quot;server close&quot;)
  })

  socket.addEventListener(&quot;close&quot;, async () =&gt; {
    console.log(&quot;server close&quot;)
  })

  socket.addEventListener(&quot;message&quot;, async (event) =&gt; {
    console.log(&quot;server message&quot;, event.data)
    await delay(1) // this seems to be important; if commented out, this works on 1.32.4
    console.log(&quot;server send&quot;, event.data)
    socket.send(event.data)
  })

  return response
}, {
  port: 0,
  signal: controller.signal,
  onListen: ({ hostname, port }) =&gt; {
    const ws = new WebSocket(`ws://${hostname}:${port}/`)

    ws.addEventListener(&quot;open&quot;, () =&gt; {
      console.log(&quot;client open&quot;)
      const data = &quot;hello world&quot;
      ws.send(data)
      console.log(&quot;client send&quot;, data)
    })

    ws.addEventListener(&quot;message&quot;, (ev) =&gt; {
      console.log(&quot;client recv&quot;, ev.data)
      controller.abort()
      ws.close()
    })

    ws.addEventListener(&quot;close&quot;, () =&gt; {
      console.log(&quot;client close&quot;)
    })
  },
})"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">delay</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"https://deno.land/std@0.183.0/async/mod.ts"</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">serve</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"https://deno.land/std@0.183.0/http/mod.ts"</span>

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-c1">version</span><span class="pl-kos">.</span><span class="pl-c1">deno</span><span class="pl-kos">)</span>

<span class="pl-k">const</span> <span class="pl-s1">controller</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">AbortController</span><span class="pl-kos">(</span><span class="pl-kos">)</span>

<span class="pl-en">serve</span><span class="pl-kos">(</span><span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-s1">request</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-k">const</span> <span class="pl-kos">{</span> response<span class="pl-kos">,</span> socket <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">upgradeWebSocket</span><span class="pl-kos">(</span><span class="pl-s1">request</span><span class="pl-kos">)</span>

  <span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">addEventListener</span><span class="pl-kos">(</span><span class="pl-s">"open"</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"server close"</span><span class="pl-kos">)</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span>

  <span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">addEventListener</span><span class="pl-kos">(</span><span class="pl-s">"close"</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"server close"</span><span class="pl-kos">)</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span>

  <span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">addEventListener</span><span class="pl-kos">(</span><span class="pl-s">"message"</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-s1">event</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"server message"</span><span class="pl-kos">,</span> <span class="pl-s1">event</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">)</span>
    <span class="pl-k">await</span> <span class="pl-en">delay</span><span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">)</span> <span class="pl-c">// this seems to be important; if commented out, this works on 1.32.4</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"server send"</span><span class="pl-kos">,</span> <span class="pl-s1">event</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">)</span>
    <span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-s1">event</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">)</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span>

  <span class="pl-k">return</span> <span class="pl-s1">response</span>
<span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
  <span class="pl-c1">port</span>: <span class="pl-c1">0</span><span class="pl-kos">,</span>
  <span class="pl-c1">signal</span>: <span class="pl-s1">controller</span><span class="pl-kos">.</span><span class="pl-c1">signal</span><span class="pl-kos">,</span>
  <span class="pl-en">onListen</span>: <span class="pl-kos">(</span><span class="pl-kos">{</span> hostname<span class="pl-kos">,</span> port <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">ws</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">WebSocket</span><span class="pl-kos">(</span><span class="pl-s">`ws://<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">hostname</span><span class="pl-kos">}</span></span>:<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">port</span><span class="pl-kos">}</span></span>/`</span><span class="pl-kos">)</span>

    <span class="pl-s1">ws</span><span class="pl-kos">.</span><span class="pl-en">addEventListener</span><span class="pl-kos">(</span><span class="pl-s">"open"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"client open"</span><span class="pl-kos">)</span>
      <span class="pl-k">const</span> <span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s">"hello world"</span>
      <span class="pl-s1">ws</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">)</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"client send"</span><span class="pl-kos">,</span> <span class="pl-s1">data</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span>

    <span class="pl-s1">ws</span><span class="pl-kos">.</span><span class="pl-en">addEventListener</span><span class="pl-kos">(</span><span class="pl-s">"message"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">ev</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"client recv"</span><span class="pl-kos">,</span> <span class="pl-s1">ev</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">)</span>
      <span class="pl-s1">controller</span><span class="pl-kos">.</span><span class="pl-en">abort</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
      <span class="pl-s1">ws</span><span class="pl-kos">.</span><span class="pl-en">close</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span>

    <span class="pl-s1">ws</span><span class="pl-kos">.</span><span class="pl-en">addEventListener</span><span class="pl-kos">(</span><span class="pl-s">"close"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"client close"</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ deno run -A repro.ts 
1.32.3
server close
client open
client send hello world
server message hello world
server send hello world
client recv hello world
server close
client close
# exits"><pre class="notranslate">$ deno run -A repro.ts 
1.32.3
server close
client open
client send hello world
server message hello world
server send hello world
client recv hello world
server close
client close
<span class="pl-c"><span class="pl-c">#</span> exits</span></pre></div>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ deno run -A repro.ts 
1.32.4
server close
client open
client send hello world
server message hello world
server send hello world
# hangs"><pre class="notranslate">$ deno run -A repro.ts 
1.32.4
server close
client open
client send hello world
server message hello world
server send hello world
<span class="pl-c"><span class="pl-c">#</span> hangs</span></pre></div>
<p dir="auto">For some reason server now only pushes at the same time the browser client pulls something.<br>
i use wss, establishing connection works fine, server onMessage works fine, but after using send on the server it just waits and does nothing until next incoming.</p>
<p dir="auto">by downgrading to 1.32.3 everything works normal again.</p>
<p dir="auto">Sidenote: with firefox websockets are waaaaay slower than with chrome.</p>