honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
20.27k stars 579 forks source link

Error with getConnInfo in Bun. #3208

Closed taisan11 closed 3 months ago

taisan11 commented 3 months ago

What version of Hono are you using?

4.5.2

What runtime/platform is your app running on?

Bun

What steps can reproduce the bug?

import { Hono } from 'hono'
import { getConnInfo } from 'hono/bun'

const app = new Hono()

app.post('/', async (c) => {
  const body = await c.req.text() //Maybe does not work if it's c.req.* with “await”.
  const IP = getConnInfo(c).remote.address
  return c.text(IP)
})

export default app

What is the expected behavior?

return IP address

What do you see instead?

Internal Server Error

Additional information

error message on console

 9 |     throw new TypeError("server.requestIP is not a function.");
10 |   }
11 |   const info = server.requestIP(c.req.raw);
12 |   return {
13 |     remote: {
14 |       address: info.address,
                    ^
TypeError: null is not an object (evaluating 'info.address')
      at getConnInfo (hono-error\node_modules\hono\dist\adapter\bun\conninfo.js:14:16)
      at hono-error\src\index.ts:8:14
EdamAme-x commented 3 months ago

It worked in my environment (Bun 1.1.18). Please give me more information of environment.

image
taisan11 commented 3 months ago

Bun version is v1.1.21

EdamAme-x commented 3 months ago

It worked on latest Bun 1.1.21.

yusukebe commented 3 months ago

Hi @taisan11

This may be a bug. I'll investigate it. Thanks for reporting.

yusukebe commented 3 months ago

This is not a Hono's bug but a Bun's matter, though I don't know if it is a real bug or not: https://github.com/oven-sh/bun/issues/11756

yusukebe commented 3 months ago

Regarding this issue, we don't have anything we can do. So, I am closing this now.

EdamAme-x commented 3 months ago

Looking at the environmental source of the issue, it seems to be a bug on bun with linux.
I'm using windows, so I may not have been able to reproduce the bug.

@taisan11 The workaround for now is to put the ip address in the Env object first. (you should use Bun.serve)

faytekin commented 3 months ago

I am experiencing the same issue. I am using macOS M3 with Bun version 1.1.21. Not being able to retrieve the IP address is a significant problem.

EdamAme-x commented 3 months ago

hi @faytekin This problem can be avoided by passing the ip address directly to the env object. Or by setting it to Variables in the frontmost middleware.

luksch42 commented 2 months ago

Update: https://github.com/oven-sh/bun/issues/11756 was fixed last week. It's working now