New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong concurrency model #40
Comments
My example seems wrong. I also got the same result using setTimeout in Node.js |
I encountered the problem of deadlock, and I guess it was caused by concurrency, but it wasn't. But my code can respond normally in std / http / server. Deadlocked in oak Deadlockedimport { Application } from "https://deno.land/x/oak/mod.ts";
const app = new Application();
app.use(async ctx => {
console.log(ctx.request.url);
if (ctx.request.url === "/ssr") {
await fetch("http://localhost:8000/hello")
.then(res => res.text())
.then(text => {
ctx.response.body = text;
});
} else {
ctx.response.body = "Hello World!";
}
});
await app.listen({ port: 8000 }); It is normalimport { serve } from "https://deno.land/std/http/server.ts";
const body = new TextEncoder().encode("Hello World\n");
for await (const req of serve(":8000")) {
console.log(req.url);
if (req.url === "/ssr") {
fetch("http://localhost:8000/hello")
.then(res => res.text())
.then(text => {
req.respond({ body: text });
});
} else {
req.respond({ body });
}
} |
Yep, that should really spin off another handleRequest async function which it uses |
This is a piece of code from Oak:
https://github.com/oakserver/oak/blob/master/application.ts#L25-L35
This incorrectly uses await for each request. As a result, requests cannot be executed in parallel, but are executed serially. If two requests are sent in succession, each of which takes 10s, eventually all requests will be completed in 20s instead of all being completed at the same time in 10s
The text was updated successfully, but these errors were encountered: