Open GJZwiers opened 1 year ago
Having this issue too. I can't use --watch with an express server because it says the port is in use after the first restart.
I think deno is too fast and it restarts the app before the express server can release the port.
I don't think it's time bound after doing some tests. I think maybe an issue with the beforeExit
event not firing?
The fix is in https://github.com/denoland/deno/pull/16616. I'll try to land that PR tonight.
This issue still exists in Deno v1.28
Still an issue in 1.28.3
Seems like it resurfaced in 1.28.3 because I can't reproduce it on 1.28.2
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.
I can confirm that I have very same issue on Windows 10 + WSL 2 linux subsystem but in my case there's additional info:
Watcher File change detected! Restarting!
error: Uncaught AddrInUse: Address already in use (os error 98)
core.runMicrotasks();
^
at Object.runMicrotasks (deno:core/01_core.js:377:30)
at processTicksAndRejections (https://deno.land/std@0.167.0/node/_next_tick.ts:62:10)
Watcher Process finished. Restarting on file change...
I'm having the same problem with linux Pop!OS
Watcher File change detected! Restarting!
error: Uncaught AddrInUse: Address already in use (os error 98)
core.runMicrotasks();
^
at Object.runMicrotasks (deno:core/01_core.js:377:30)
at processTicksAndRejections (https://deno.land/std@0.167.0/node/_next_tick.ts:62:10)
I'm having the same problem with linux Pop!OS
Watcher File change detected! Restarting! error: Uncaught AddrInUse: Address already in use (os error 98) core.runMicrotasks(); ^ at Object.runMicrotasks (deno:core/01_core.js:377:30) at processTicksAndRejections (https://deno.land/std@0.167.0/node/_next_tick.ts:62:10)
Can confirm same bug still present on macOS.
deno 1.29.1 (release, x86_64-apple-darwin) v8 10.9.194.5 typescript 4.9.4
still same error on deno 1.29.2 (release, x86_64-pc-windows-msvc)
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.
no longer an issue on 1.31.0.
Cannot reproduce anymore either, I will close this now.
i found this issue is still there while using the unstable FlashServer
await Deno.serve(() => new Response("Hello World!"));
deno run -A --unstable --watch main.ts
Watcher File change detected! Restarting!
error: Uncaught (in promise) AddrInUse: Address already in use (os error 48)
Watcher Process finished. Restarting on file change...
Same here with the basic test suggested by @ynwd...
~ deno -V
deno 1.31.2
~ deno run -A --unstable --watch main.ts
Watcher Process started.
Listening on http://127.0.0.1:9000/
# edit main.ts
Watcher File change detected! Restarting!
error: Uncaught AddrInUse: Address already in use (os error 98)
Watcher Process finished. Restarting on file change...
~ sudo netstat -tanup | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 143534/deno
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.
import { Server } from 'https://deno.land/std@0.179.0/http/server.ts'
const handler = () => new Response('Hello World!')
const hostname = 'localhost'
const port = 8080
const server = new Server({ hostname, port, handler })
console.log(`Starting to listen on port ${port}`)
server.listenAndServe()
globalThis.addEventListener('unload', () => {
server.close()
})
@sstiglitz would you have any idea how this strategy could be applied to Deno Fresh?
Still an issue with the latest version.
Still an issue
Watcher File change detected! Restarting! error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'port') port = (server.addrs[0] as Deno.NetAddr).port; ^ at serve (https://deno.land/std@0.150.0/http/server.ts:591:44) at start (https://deno.land/x/fresh@1.1.4/src/server/mod.ts:70:11) at async file:///Users/christianangelosulit/Documents/GitHub/kmc/deno_project/my-project/main.ts:13:1 Watcher Process finished. Restarting on file change... ^C xxx@Christians-MacBook-Pro-2 my-project % xxx@Christians-MacBook-Pro-2 my-project % xxx@Christians-MacBook-Pro-2 my-project % deno upgrade Looking up latest version Local deno version 1.31.2 is the most recent release
For now, until the issue is fixed, the easiest workaround is to downgrade to v1.30.0
sudo deno upgrade --version 1.30.0
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.
For brew users, the workaround is:
# the cask version that pointed to deno@1.30.0
FORMULA_URL='https://raw.githubusercontent.com/Homebrew/homebrew-core/2b3035ebfc70660dc8753678b43404d5d8016f99/Formula/deno.rb'
# get the .rb file locally
curl -O $FORMULA_URL
# replace the installed deno with the v1.30.0 version
brew uninstall deno
brew install ./deno.rb
# the cask version that pointed to deno@1.30.0
Do you have an URL to deno@1.31.1 because that for me was the last version without this error. How did you get the URL to the old formula version?
EDIT: Just noticed the version you linked is 1.31.0, so that difference should be fine by me for now. Thanks for the workaround.
I had the same issue here after I upgraded to 1.31.1 so I downgraded to 1.31.0 since it was working fine for me. Just stay at 1.31.0 until we have a fix.
I had the same issue here after I upgraded to 1.31.1 so I downgraded to 1.31.0 since it was working fine for me. Just stay at 1.31.0 until we have a fix.
Thanks, 1.31.0 is normal. I had a problem with the update to 1.31.2 before, and I feel that this kind of problem should not have happened
Same problem on version 1.31.2
with fresh
The issue is fixed on version 1.31.3
so closing this, but the Deno.serve
bug seems to be there still, for which https://github.com/denoland/deno/issues/16267 is still open.
Can reproduce it as well on 1.32.3, reopening issue.
@GJZwiers this problem has been fixed and will be released in v1.32.4 next week.
@bartlomieju Thanks, it seems fixed indeed. I will close this again after 1.32.4 is released.
Hi all. Until the next week release, I found a solution by using the serveListener
(v 1.32.3):
import { serveListener } from "https://deno.land/std@0.182.0/http/server.ts";
const listener = Deno.listen({ port: 8080 })
serveListener(listener, (req) => {
console.log("handling", JSON.stringify(req.url))
return new Response("hello there!", { status: 200 })
})
Cheers!
EDIT: remove await
before serveListener
RE-EDIT: seems unstable too at this point
Same problem on version 1.33.2:
➜ express5 deno --version
deno 1.33.2 (release, x86_64-apple-darwin)
v8 11.4.183.1
typescript 5.0.3
import express from "npm:express"
const app = express()
app.get('/', (req, res) => {
res.send('hello world')
})
app.listen(3000)
console.log("Serve is listen on port: ", 3000)
I'm having the same issue 😕
See https://github.com/denoland/deno/issues/18960, it will be fixed next week.
still in 1.33.2 at my koa project, but doing this its woking..
const server = app.listen(PORT)
addEventListener('unload', () => {
server.close()
})
@bartlomieju I'm still having the same issue while using fresh@1.1.2, as of the latest commit (including #18998) built with cargo build --release
, WSL on Windows 11 with Ubuntu 22.04.2 LTS.
CC @mmastrac
@lionel-rowe was that a debug or release build?
Release (cargo build --release
)
same thing in 1.34.3
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
Same issue on recent Deno versions. I am on MacOS 14.2. It makes the watcher completely unusable sadly
Same issue on Deno v1.43.3. I use Apllo server and expressjs on Linux debian 12. It's like every refresh opens a different thread. Each opened thread is giving a different addrinuse error.
Having this issue with Deno.serve and a Hono router in Deno v1.45.4.
Also, my Deno.serve is still running even though I've exited the terminal completely – maybe related?
Reproducable with adding
addEventListener("hmr", (e) => {
console.log("HMR triggered", e);
});
Source: https://stackoverflow.com/questions/74444443/deno-watcher-uncaught-addrinuse-only-one-usage-of-each-socket-address
Reproduction:
deno run -A --watch server.ts
: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