hapijs / hapi

The Simple, Secure Framework Developers Trust
https://hapi.dev
Other
14.63k stars 1.34k forks source link

Bun – POST request returns 500 status code #4463

Closed raphael-papazikas closed 5 months ago

raphael-papazikas commented 1 year ago

Support plan

Context

What are you trying to achieve or the steps to reproduce?

Experimenting with bun.

import * as Hapi from '@hapi/hapi';

// this is necessary, because bun does not support this perf_hooks api right now
// <https://github.com/oven-sh/bun/issues/5804>
const PerfHooks = require('perf_hooks');
PerfHooks.performance.eventLoopUtilization = function() {}

const init = async () => {
    const server = Hapi.server({
        port: 4000,
        host: 'localhost'
    });

    server.route({
        path: "/api/test",
        method: "POST",
        handler: function() {
            console.log("successful")
            return {status: "ok"}
        }
    })

    await server.start();
    console.log('Server running on %s', server.info.uri);
};

init();

Steps to reproduce

What was the result you got?

Received 500 status code from the server. Seems like it throws through this line in wreck: https://github.com/hapijs/wreck/blob/f53808548f8253c194da0f32ac9ae3d986e86d79/lib/index.js#L434 => https://github.com/hapijs/wreck/blob/f53808548f8253c194da0f32ac9ae3d986e86d79/lib/index.js#L429C18-L429C18

What result did you expect?

I would expect the same behavior as for node environment

damusix commented 7 months ago

@raphael-papazikas If a nodejs replica doesn't run Hapi, but Hapi runs in anything Node 16+, then it's not Hapi, it's the nodejs replica. I think the onus is on you guys to find out where the issue lies and report it to the Bun team. You may be solving a critical problem where Bun does not in fact behave like NodeJS.

reedspool commented 5 months ago

Unable to repro today on Bun 1.1.10 & @hapi/hapi version 21.3.9

Server code above prints "successful" and curl response is {"status":"ok"}

damusix commented 5 months ago

@reedspool @raphael-papazikas seems like this is no longer an issue with newer versions of Bun.