<p dir="auto">I am testing new native HTTP/2 server and got a problem while trying to handle requests asynchronously, I am just can't get the response. My code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const listener = Deno.listenTls({
    port: 2022,
    certFile: &quot;./localhost.pem&quot;,
    keyFile: &quot;./localhost-key.pem&quot;,
    alpnProtocols: [&quot;h2&quot;, &quot;http/1.1&quot;],
  });
  
  for await (const conn of listener) {
    handleConn(conn);
  }
  
  async function handleConn(conn: Deno.Conn) {
    const httpConn = Deno.serveHttp(conn);
    for await (const c of httpConn) {
      handleHttpConn(c);
    }
  }

  async function handleHttpConn(conn: Deno.RequestEvent) {
    await Promise.resolve(); // pretending to do some looooong job
    conn.respondWith(new Response(`Responding to ${conn.request.url}`));
  }"><pre class="notranslate"><code class="notranslate">const listener = Deno.listenTls({
    port: 2022,
    certFile: "./localhost.pem",
    keyFile: "./localhost-key.pem",
    alpnProtocols: ["h2", "http/1.1"],
  });
  
  for await (const conn of listener) {
    handleConn(conn);
  }
  
  async function handleConn(conn: Deno.Conn) {
    const httpConn = Deno.serveHttp(conn);
    for await (const c of httpConn) {
      handleHttpConn(c);
    }
  }

  async function handleHttpConn(conn: Deno.RequestEvent) {
    await Promise.resolve(); // pretending to do some looooong job
    conn.respondWith(new Response(`Responding to ${conn.request.url}`));
  }
</code></pre></div>
<p dir="auto">When I am using simple non-async function everything works fine.</p>
<p dir="auto">Essentially the same as what's happening in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="728792966" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/8107" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/8107/hovercard" href="https://github.com/denoland/deno/issues/8107">#8107</a>, but when using <code class="notranslate">Deno.listenTls()</code>. I noticed that issue was closed but the problem is still persisting. Every once in a while, the server will output errors like,</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Sending fatal alert HandshakeFailure"><pre class="notranslate"><code class="notranslate">Sending fatal alert HandshakeFailure
</code></pre></div>
<p dir="auto">or</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Illegal SNI hostname received [49, 53, 57, 46, 56, 57, 46, 50, 50, 46, 50, 51, 57]
Sending fatal alert DecodeError"><pre class="notranslate"><code class="notranslate">Illegal SNI hostname received [49, 53, 57, 46, 56, 57, 46, 50, 50, 46, 50, 51, 57]
Sending fatal alert DecodeError
</code></pre></div>
<p dir="auto">Eventually after a while, the TLS listener will simply hang and will cease to receive new connections (the following loop will cease to progress),</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const listener = Deno.listenTls(/* ... */);
for await (const connection of listener)
    /* this loop freezes */"><pre class="notranslate"><code class="notranslate">const listener = Deno.listenTls(/* ... */);
for await (const connection of listener)
    /* this loop freezes */
</code></pre></div>
<p dir="auto">This doesn't happen with a non-TLS listener (using <code class="notranslate">Deno.listen()</code>). I belive <code class="notranslate">std/http</code> has a similar problem. Previously, this would cause the server to crash completely, so at least there was a workaround in putting the server in an infinite loop to restart whenever it crashes, but since it just causes the loop to hang, this is not really an option without resorting to something much more complicated.</p>