GithubHelp home page GithubHelp logo

Comments (2)

Gakai avatar Gakai commented on June 8, 2024

We could solve the problem in our application by providing a custom Server implementation.
I think it would be reasonable to add this change to the default implementation as well.

The relevant difference to the http_server_bun.ts implementation is that we added an abort signal listener in the ReadableStream.start function, that closes the stream AND the server:

listen(): Listener | Promise<Listener> {
    if (this.#server) {
        throw new Error("Server already listening.");
    }
    const { onListen, hostname, port, signal } = this.#options;
    const tls = isServeTlsOptions(this.#options)
        ? { key: this.#options.key, cert: this.#options.cert }
        : undefined;
    const { promise, resolve } = createPromiseWithResolvers<Listener>();
    this.#stream = new ReadableStream<BunRequest>({
        start: (controller) => {
            this.#server = Bun.serve({
                fetch(req, server) {
                    const request = new BunRequest(req, server);
                    controller.enqueue(request);
                    return request.response;
                },
                hostname,
                port,
                tls,
            });
            signal?.addEventListener("abort", () => {
                controller.close();
                this.close();
            }, { once: true });
            {
                const { hostname, port } = this.#server;
                if (onListen) {
                    onListen({ hostname, port });
                }
                resolve({ addr: { hostname, port } });
            }
        },
    });
    return promise;
}

from oak.

olee avatar olee commented on June 8, 2024

Btw: The nodejs server implementation seems to suffer from the same issue.

from oak.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.