deno: Uncaught AddrInUse when restarting server in watch mode after saving file
Reproduction:
- Run the code below with
deno run -A --watch server.ts
:
import express, { Express, Request, Response } from "npm:express@4.18";
import { v4 as uuidv4 } from 'npm:uuid@9.0.0';
const app: Express = express();
app.use("/", (_req: Request, res: Response) => {
res.send(`uuid: ${uuidv4()}.`);
})
app.listen(8000, () => {
console.log("App Running: http://localhost:8000");
});
- Make a change and save the file (either with auto-save or manually)
- When the file watcher restarts the error is thrown
Watcher File change detected! Restarting!
error: Uncaught AddrInUse: Only one usage of each socket address (protocol/network address/port) is normally permitted. (os error 10048)
Watcher Process finished. Restarting on file change...
I found that this error can happen when there is another process listening on the same port: https://stackoverflow.com/a/62190276/12769288, so maybe the file watcher tries to restart the server while the previous one is still listening?
Additionally the same error seems to happen on occasion in one of the tests: https://github.com/denoland/deno/issues/16044
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 3
- Comments: 44 (15 by maintainers)
Commits related to this issue
- fix(ext/http): Ensure Deno.serve works across --watch restarts (#18998) Fixes #16699 and #18960 by ensuring that we release our HTTP `spawn_local` tasks when the HTTP resource is dropped. Because... — committed to denoland/deno by mmastrac a year ago
- fix(ext/http): Ensure Deno.serve works across --watch restarts (#18998) Fixes #16699 and #18960 by ensuring that we release our HTTP `spawn_local` tasks when the HTTP resource is dropped. Because... — committed to denoland/deno by mmastrac a year ago
The work to fix this issue is being done out-of-bounds in another repo. We expect to ship the rewrite in v1.31 in February.
@GJZwiers this problem has been fixed and will be released in v1.32.4 next week.
I had to revert the PR that fixed it because it introduced another problems. We’re working on a rewrite of the server that should fix this problem.
For the people getting this issue when using
std/http/server.ts
, the issue should get fixed in the next patch release.For the people getting this issue when using
Deno.serve
, I have made a separate issue: https://github.com/denoland/deno/issues/18186.@Csulit It seems you are getting a different kind of error message, possibly a bug in Fresh. I suggest creating an issue over in that repository.
See https://github.com/denoland/deno/issues/18960, it will be fixed next week.
@bartlomieju Thanks, it seems fixed indeed. I will close this again after 1.32.4 is released.
I can confirm that I have very same issue on Windows 10 + WSL 2 linux subsystem but in my case there’s additional info:
The fix is in https://github.com/denoland/deno/pull/16616. I’ll try to land that PR tonight.
Sill an issue in Ubuntu on Deno 1.40 when you kill the process with Ctrol+C and launch it again. It requires to
killall -9 deno
CC @mmastrac
Same problem on version 1.33.2:
Can reproduce it as well on 1.32.3, reopening issue.
The issue is fixed on version
1.31.3
so closing this, but theDeno.serve
bug seems to be there still, for which https://github.com/denoland/deno/issues/16267 is still open.For now, until the issue is fixed, the easiest workaround is to downgrade to v1.30.0
I ran into the same problem on 1.31.1, upgraded to 1.31.2 with fingers crossed, but same thing.
As a workaround to the problem, this seems to work for me.
Same here with the basic test suggested by @ynwd…
i found this issue is still there while using the unstable FlashServer
I’m having the same problem with linux Pop!OS