<p dir="auto">This was reported in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1454893304" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/16699" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/16699/hovercard" href="https://github.com/denoland/deno/issues/16699">#16699</a> but while the error is fixed on the canary when using <code class="notranslate">std/http/server.ts</code> it remains when using <code class="notranslate">Deno.serve</code>. Therefore, I am making this issue to separate concerns.</p>
<p dir="auto">Repro:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="await Deno.serve(() =&gt; new Response(&quot;Hello World!&quot;));"><pre class="notranslate"><span class="pl-k">await</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">serve</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-k">new</span> <span class="pl-smi">Response</span><span class="pl-kos">(</span><span class="pl-s">"Hello World!"</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deno run --allow-net --unstable --watch server.ts"><pre class="notranslate"><code class="notranslate">deno run --allow-net --unstable --watch server.ts
</code></pre></div>
<p dir="auto">After making file changes to <code class="notranslate">server.ts</code> and saving it shows:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Watcher File change detected! Restarting!
error: Uncaught AddrInUse: Address already in use (os error 98)
Watcher Process finished. Restarting on file change..."><pre class="notranslate"><code class="notranslate">Watcher File change detected! Restarting!
error: Uncaught AddrInUse: Address already in use (os error 98)
Watcher Process finished. Restarting on file change...
</code></pre></div>
<p dir="auto">When running this code</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Deno.serve(() =&gt; {}, { port: x })"><pre class="notranslate"><span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">serve</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-kos">}</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">port</span>: <span class="pl-s1">x</span> <span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">with this command</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="deno run -A --unstable --watch script.ts"><pre class="notranslate">deno run -A --unstable --watch script.ts</pre></div>
<p dir="auto">I get this error everytime i make a change and have to kill the script (ctrl + c) and run it again.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Watcher File change detected! Restarting!
error: Uncaught (in promise) AddrInUse: Address already in use (os error 98)
Watcher Process finished. Restarting on file change..."><pre class="notranslate"><code class="notranslate">Watcher File change detected! Restarting!
error: Uncaught (in promise) AddrInUse: Address already in use (os error 98)
Watcher Process finished. Restarting on file change...
</code></pre></div>
<p dir="auto">deno 1.26.1 (release, x86_64-unknown-linux-gnu)<br>
Linux Fedora 37</p>