koajs / koa

Expressive middleware for node.js using ES2017 async functions
https://koajs.com
MIT License
35.07k stars 3.22k forks source link

async issue on app.listen(...) #1783

Closed Lucyfurnice closed 9 months ago

Lucyfurnice commented 10 months ago

Describe the bug

app.listen happens after process.exit Node.js version: v18.18.2 LTS OS version: Microsoft Windows [Version 10.0.22621.2428] Description: Process.exit is happening before app.listen(...)

Actual behavior

app.listen(...) happens after process.exit(...)

Expected behavior

app.listen loops until ctrl+c then main function returns error code, and then process exits with main function error code.

Code to reproduce

lucyfurnice/koa-test

Checklist

prashant5025 commented 10 months ago

https://github.com/Lucyfurnice/koa-test link is not working please fix your repo link with https://github.com/Lucyfurnice/koa-test/blob/main/core.js/application.js now it will work fine 👍

Lucyfurnice commented 10 months ago

https://github.com/Lucyfurnice/koa-test link is not working please fix your repo link with https://github.com/Lucyfurnice/koa-test/blob/main/core.js/application.js now it will work fine 👍

oops, I put the markup backwards. I don't even think this is an issue with koa I think I need to ask on https://github.com/nodejs/node.

Lucyfurnice commented 10 months ago

after reviewing the library source for net.Server and http.Server I have determined that it may be due to net.Server extending EventEmitter, and then emitting an event on listen, however the code I looked at ( setupListenHandler(...) & Server.prototype.listen = function(...args) ) does not appear to be asynchronous.

iwanofski commented 9 months ago

I realise you've done some investigation yourself and pretty much answered your own question. But just to confirm before I close the issue, yes, it'n not necessarily a bug but just a side effect of how events works! I'm closing this issue but feel free re-open if I misunderstood this ticket as "invalid".