<p dir="auto">Piping ReadableStream through TextDecoderStream leaks resource as demonstrated with following test:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Deno.test(&quot;leaks&quot;, async () =&gt; {
  const res = await fetch(
    &quot;https://deno.land/std@0.186.0/json/testdata/test.jsonl&quot;
  )

  const textStream = new TextDecoderStream()
  const reader = res.body!.pipeThrough(textStream).getReader()
  const t = await reader.read()

  await reader!.cancel()
})"><pre class="notranslate"><span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">"leaks"</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-k">const</span> <span class="pl-s1">res</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-en">fetch</span><span class="pl-kos">(</span>
    <span class="pl-s">"https://deno.land/std@0.186.0/json/testdata/test.jsonl"</span>
  <span class="pl-kos">)</span>

  <span class="pl-k">const</span> <span class="pl-s1">textStream</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">TextDecoderStream</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
  <span class="pl-k">const</span> <span class="pl-s1">reader</span> <span class="pl-c1">=</span> <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-c1">body</span><span class="pl-c1">!</span><span class="pl-kos">.</span><span class="pl-en">pipeThrough</span><span class="pl-kos">(</span><span class="pl-s1">textStream</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">getReader</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
  <span class="pl-k">const</span> <span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">reader</span><span class="pl-kos">.</span><span class="pl-en">read</span><span class="pl-kos">(</span><span class="pl-kos">)</span>

  <span class="pl-k">await</span> <span class="pl-s1">reader</span><span class="pl-c1">!</span><span class="pl-kos">.</span><span class="pl-en">cancel</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">Run <code class="notranslate">deno test stream-test.ts</code> and you will get:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: Leaking resources:
  - A text decoder (rid 6) was created during the test, but not finished during the test. Close the text decoder by calling `textDecoder.decode('')` or `await textDecoderStream.readable.cancel()`."><pre class="notranslate"><code class="notranslate">error: Leaking resources:
  - A text decoder (rid 6) was created during the test, but not finished during the test. Close the text decoder by calling `textDecoder.decode('')` or `await textDecoderStream.readable.cancel()`.
</code></pre></div>
<p dir="auto">Adding <code class="notranslate">await t.readable.cancel()</code> as error message suggested does not help.</p>
<p dir="auto">A following solution with manual decoding works properly:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Deno.test(&quot;working alternative&quot;, async () =&gt; {
  const res = await fetch(
    &quot;https://deno.land/std@0.186.0/json/testdata/test.jsonl&quot;
  )

  const textDecoder = new TextDecoder()
  const reader = res.body!.getReader()
  const b = await reader.read()
  const t = await textDecoder.decode(b.value!)

  await reader.cancel()
})"><pre class="notranslate"><span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">"working alternative"</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-k">const</span> <span class="pl-s1">res</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-en">fetch</span><span class="pl-kos">(</span>
    <span class="pl-s">"https://deno.land/std@0.186.0/json/testdata/test.jsonl"</span>
  <span class="pl-kos">)</span>

  <span class="pl-k">const</span> <span class="pl-s1">textDecoder</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">TextDecoder</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
  <span class="pl-k">const</span> <span class="pl-s1">reader</span> <span class="pl-c1">=</span> <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-c1">body</span><span class="pl-c1">!</span><span class="pl-kos">.</span><span class="pl-en">getReader</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
  <span class="pl-k">const</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">reader</span><span class="pl-kos">.</span><span class="pl-en">read</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
  <span class="pl-k">const</span> <span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">textDecoder</span><span class="pl-kos">.</span><span class="pl-en">decode</span><span class="pl-kos">(</span><span class="pl-s1">b</span><span class="pl-kos">.</span><span class="pl-c1">value</span><span class="pl-c1">!</span><span class="pl-kos">)</span>

  <span class="pl-k">await</span> <span class="pl-s1">reader</span><span class="pl-kos">.</span><span class="pl-en">cancel</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">I spent whole evening last night to make it work and ended up with latter piece. Shouldn't closing initial stream also close all subsequent ones? Either way, closing readable TextDecoderStream doesn't work too.</p>
<p dir="auto">Deno version: 1.33.2 and 1.33.1</p>
<p dir="auto">When configuring a server with a cloudflare origin server certificate, it works perfectly when you visit the site using the url with https:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/17011087/82387270-31879980-99fc-11ea-8ab7-f76f8054b7ae.png"><img src="https://user-images.githubusercontent.com/17011087/82387270-31879980-99fc-11ea-8ab7-f76f8054b7ae.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">But when directly visiting the server IP using https the process stops on the server with the following error:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/17011087/82387291-3c422e80-99fc-11ea-9b27-3fe221234b78.png"><img src="https://user-images.githubusercontent.com/17011087/82387291-3c422e80-99fc-11ea-9b27-3fe221234b78.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">Would it be possible to ignore that error so that the server continues to run?<br>
The connection may close or return an error message, but the server should continue to listen to other requests.</p>
<p dir="auto">I hope you have a solution! regards</p>